Hello I just did CodeChief's candy splitting task here and my code is working even with alota lot of test cases and big numbers, but it uses way too much memory, when. When I checked my submission, it was 1342M, which is alota lot. So here is my code :
import java.util.ArrayList;
import java.util.Scanner;
class Candies {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int candieStuds;
int candieT;
int testCases = in.nextInt();
ArrayList<String> answ = new ArrayList<String>();
for(int tCase = 0; tCase < testCases; tCase++){
int candies = in.nextInt();
int studs = in.nextInt();
candieStuds = candies/studs;
candieT = candies%studs;
StringBuilder str = new StringBuilder();
str.append(candieStuds);
str.append(" ");
str.append(candieT);
answ.add(str.toString());
}
for(int listInd = 0; listInd < answ.size(); listInd++){
System.out.println(answ.get(listInd));
}
in.close();
}}
So here is my question canCan someone point out what I should use so I can have the same prefomanceperformance but use less memory? I will appriciate every answear :)