이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
#include <stack>
#include <limits.h>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <cstring>
#include <sstream>
#pragma GCC target("popcnt")
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=1e9+7;
typedef pair<ll,ll>point;
//#define x first
//#define y second
struct E{
int cores;
int hz;
int money;
};
int n,m;
E computers[2000];
E people[2000];
bool cmp(E&a,E&b){
return a.hz>b.hz;
}
ll dp1[3000][200];
ll dp2[3000][200];
int main(){
ios::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
//freopen("speeding.in","r",stdin);
//freopen("speeding.out","w",stdout);
cin>>n;
for(int i=0;i<n;i++)
cin>>computers[i].cores>>computers[i].hz>>computers[i].money;
cin>>m;
for(int i=0;i<m;i++)
cin>>people[i].cores>>people[i].hz>>people[i].money;
sort(computers,computers+n,cmp);
sort(people,people+m,cmp);
for(int p=m-1;p>=0;p--){
for(int cores=0;cores<99;cores++){
ll res=dp2[p+1][cores];
if(people[p].cores<=cores)
res=max(res,dp2[p+1][cores-people[p].cores]+people[p].money);
dp2[p][cores]=res;
}
}
for(int c=n-1;c>=0;c--){
for(int p=m-1;p>=0;p--){
for(int cores=0;cores<200;cores++){
ll res=0;
res=max(res,dp2[p][cores]);
res=max(res,dp1[p+1][cores]);
if(people[p].cores<=cores)
res=max(res,dp1[p+1][cores-people[p].cores]+people[p].money);
if(computers[c].hz>=people[p].hz&&cores+computers[c].cores<200)
res=max(res,dp2[p][cores+computers[c].cores]-computers[c].money);
dp1[p][cores]=res;
}
}
memcpy(dp2,dp1,sizeof(dp1));
}
cout<<dp1[0][0]<<"\n";
return 0;
}
/*
4
4 2200 700
2 1800 10
20 2550 9999
4 2000 750
3
1 1500 300
6 1900 1500
3 2400 4550
*/
# | 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... |