Submission #824187

#TimeUsernameProblemLanguageResultExecution timeMemory
824187Username_taken12Cloud Computing (CEOI18_clo)Java
18 / 100
327 ms262144 KiB
import java.io.*; import java.util.*; public class clo { static int val=1000; public static void main(String[] args) throws IOException { BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); ArrayList<int[]> t = new ArrayList<>(); int N = Integer.parseInt(r.readLine()); for(int i=0; i<N; i++) { StringTokenizer st = new StringTokenizer(r.readLine()); //cores clockspeed price int[] add = new int[]{Integer.parseInt(st.nextToken()), -1*Integer.parseInt(st.nextToken()), -1*Integer.parseInt(st.nextToken())}; t.add(add); } int M = Integer.parseInt(r.readLine()); for(int i=0; i<M; i++){ StringTokenizer st = new StringTokenizer(r.readLine()); int[] add = new int[]{-1*Integer.parseInt(st.nextToken()), -1*Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken())}; t.add(add); } Collections.sort(t, new Comp()); //for(int i=0; i<t.size(); i++) // System.out.println(Arrays.toString(t.get(i))); long[][] dp = new long[N+M+1][val*50+1]; for(int i=0; i<N+M+1; i++) for(int j=0; j<val*50+1; j++) dp[i][j]=Long.MIN_VALUE/2; dp[0][0]=0; for(int i=0; i<N+M; i++) for(int j=0; j<val*50+1; j++){ if(dp[i][j]!=Long.MIN_VALUE/2&&((t.get(i)[0]+j)>=0)){ dp[i+1][j+t.get(i)[0]]=Math.max(dp[i+1][j+t.get(i)[0]], dp[i][j]+t.get(i)[2]); } dp[i+1][j]=Math.max(dp[i][j], dp[i+1][j]); } /*for(int i=0; i<N+M; i++){ for(int j=0; j<40; j++) System.out.print(dp[i][j]+" "); System.out.println(); }*/ long max=0; for(int j=0; j<val*50+1; j++) { max=Math.max(dp[N+M][j], max); } pw.println(max); pw.close(); } } class Comp implements Comparator<int[]>{ public int compare(int[] a , int[] b){ return Integer.compare(a[1], b[1]); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...