This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define P(a) do{if(debug) cout<<a<<endl;} while(false)
#define H(a) P(#a<<": "<<a)
#define FR(i,a,b) for(int i = (a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define f first.first
#define c first.second
#define v second
#define ppiii pair<pair<int,int>, int>
const bool debug = 0;
const int inf = 1e9;
using namespace std;
int n,m;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
vector<ppiii> comp(n);
F(i,n){
cin>>comp[i].c>>comp[i].f>>comp[i].v;
}
cin>>m;
vector<ppiii> task(m);
F(i,m){
cin>>task[i].c>>task[i].f>>task[i].v;
}
sort(comp.begin(), comp.end());
sort(task.begin(), task.end());
int dp[n+2][m+2][105];
F(i,n+2) F(j,m+2) F(k,105) dp[i][j][k] = -inf;
F(i,51) F(j,m+1){
dp[n][j][i] = 0;
}
F(i,51) F(j,n+1){
dp[j][m][i] =0;
}
for(int i = n-1; i>=0; i--){//the computer we are deciding to take or not
for(int j = m-1; j>=0; j--){ //the task we are deciding to take or not
for(int k = 100; k>=0; k--){ //the amount of cores still needed from the last task / - the amount of cores still left + 50
if(k>=50){ //there are still cores needed for the last task
dp[i][j][k] = max(dp[i+1][j][k-comp[i].c]-comp[i].v, dp[i+1][j][k]); //take or don't take the computer
}
else if(i>0){ //there are cores left from the last computer (i-1)
if(comp[i-1].f < task[j].f){
P("a");
dp[i][j][k] = dp[i][j][50]; //the clockspeed from the last computer is not good enough
}
else{
P("b");
dp[i][j][k] = max(dp[i][j+1][k],dp[i][j+1][k+task[j].c]+task[j].v);
}
/*if(i==3 && j == 2 && k == 50-4) {
H(dp[i][j+1][k]);
H(dp[i][j+1][k+task[j].c]);
H(task[j].v);
H(dp[i][j][50]);
H(dp[i][j][k]);
}*/
}
}
}
}
cout<<dp[0][0][50]<<endl;
H(dp[2][2][50]);
H(dp[3][2][50]);
H(dp[3][2][46]);
H(comp[2].v);
/*while(true){
int i,j,k;
cin>>i>>j>>k;
cout<<dp[i][j][k+50]<<endl;
}*/
return 0;
}
# | 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... |