이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
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 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... |