/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
//package PracticeMedium;
import java.util.Scanner;
/**
*
* @author Hemant Dhanuka
*/
class COINS {
long maximumvalue[] = new long[500000001];
// maximumvalue=new long[1000000001];
public static void main(String[] args) throws Exception {
COINS c = new COINS();
c.calculateMaxforEachNo();
// calculateMaxforEachNo();
Scanner s = new Scanner(System.in);
while (s.hasNextInt()) {
int numberWrittenOnCoin = s.nextInt();
System.out.println(c.maximumvalue[numberWrittenOnCoin]);
}
}
private void calculateMaxforEachNo() {
for (int i = 0; i < maximumvalue.length; i++) {
int n1 = i / 2;
int n2 = i / 3;
int n3 = i / 4;
long checkingmax = maximumvalue[n1] + maximumvalue[n2] + maximumvalue[n3];
if (checkingmax > i) {
maximumvalue[i] = checkingmax;
} else {
maximumvalue[i] = i;
}
// System.out.println(i);
}
}
}
i am getting error as as–
Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
at COINS.(COINS.java:15)
at COINS.main(COINS.java:19)
C:\Users\Hemant Dhanuka\AppData\Local\NetBeans\Cache\8.1\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)
is there anyother solution in which i will not encounter this heapMemoryFinishedError…
or Tell me what modification i do to run successufully my program and submit it on codechef accurately