This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import java.io.*;
import java.util.*;
public class clo {
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][2000*50+1];
for(int i=0; i<N+M+1; i++)
for(int j=0; j<2000*50+1; j++)
dp[i][j]=Long.MIN_VALUE;
dp[0][0]=0;
for(int i=0; i<N+M; i++)
for(int j=0; j<2000*50+1; j++){
if(dp[i][j]!=Long.MIN_VALUE&&((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<2000*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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |