Thanks, this is great!
What are some of the best resources/books to get good at CP according to you? What are the ones that you used/liked the most? How did you start with CP? What were the main problems faced in this journey? How did you overcome them? Thanks :)
Thanks Keshav Sir. I tried solving the problem in Java, but I'm getting wrong answers. Can you please help me?
Thanks :)
import java.io.*;class Round_Table2{public static long cost(int angry, int i, int arthur, int a[],long b[][]){if(i==a.length) //Dont really need thisreturn 0;if(i==a.length-1){if(angry==1||arthur==1)b[i][angry]=a[i];elseb[i][angry]=0;}if(b[i][angry]==-1){if(i==0)
Hey Swetanjal. Thanks. But can you please tell me what is wrong with my code in Java? I am getting a runtime(NZEC) on the 1st task (tasks are from 0-11). thanks!
import java.io.*;class SUPW_memoization{public static int compute(int pending, int i, int a[],int b[][]){if(i<a.length){if(pending==2){if(b[i][pending]==-1)b[i][pending]=compute(0,i+1,a,b)+a[i];return b[i][pending];}if(b[i][pending]==-1)b[i][pending]= (int)(Math.min(compute(pending+1,i+1,a,b),compute(0,i+1,a,b)+a[i]));return b[i][pending];}
Also any tip to improve my coding style?
Can someone please help me? I fail to understand why I am getting wrong answer in this Java code.
import java.io.*;import java.util.*;class Bookshelves{public static int compute(int a[],int b[],int N,int k){int i,skew=a[N-1]+b[N-1],c,d,pos1=N-1,pos2=0;for(i=0;i<k;i++){if(N-i>1){if(a[pos1--]>b[pos2++])skew=b[N-1]+a[pos1];elsebreak;}elsebreak;}return skew;}public static void main(String args[]) throws IOException{BufferedReader br=new BufferedReader(new InputStreamReader(System.in));int i,j=0,N,k;String s[];System.out.println();s=br.readLine().trim().split(" ");N=Integer.parseInt(s[0].trim());k=Integer.parseInt(s[1].trim());if(N!=0){int a[]=new int[N];int b[]=new int[N];for(i=2;i<N+2;i++)a[j++]=Integer.parseInt(s[i].trim());j=0;for(i=N+2;i<2*N+2;i++)b[j++]=Integer.parseInt(s[i].trim());Arrays.sort(a);Arrays.sort(b);if(a[N-1]<b[N-1])System.out.println(compute(a,b,N,k));elseSystem.out.println(compute(b,a,N,k));}elseSystem.out.println(0);}}