Skip to main content
deleted 88 characters in body; edited title
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

Candy splitting. Lower - lower memory usage needed CodeChief

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 :)

Candy splitting. Lower memory usage needed CodeChief

Hello I just did CodeChief's candy splitting task here and my code is working even with alot of test cases and big numbers but it uses way too much memory, when I checked my submission it was 1342M which is alot. 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 can someone point out what I should use so I can have the same prefomance but use less memory? I will appriciate every answear :)

Candy splitting - lower memory usage needed

I just did CodeChief's candy splitting task here and my code is working even with a lot of test cases and big numbers, but it uses way too much memory. When I checked my submission, it was 1342M, which is a lot.

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();
}}

Can someone point out what I should use so I can have the same performance but use less memory?

Source Link

Candy splitting. Lower memory usage needed CodeChief

Hello I just did CodeChief's candy splitting task here and my code is working even with alot of test cases and big numbers but it uses way too much memory, when I checked my submission it was 1342M which is alot. 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 can someone point out what I should use so I can have the same prefomance but use less memory? I will appriciate every answear :)