이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
struct order{
int cores;
int fr;
int val;
int type; // type == 1 => computer, type == 2>= order
bool operator< (const order &q) const {
if(fr == q.fr){
return type > q.type;
}
return fr < q.fr;
}
};
const int M = (int)2e5+10;
const ll inf = (ll)1e18;
ll dp[M];
int main(){
fastIO;
int n;
cin >> n;
int c, f, v;
vector<order> ff;
for(int i = 0 ; i < n; i ++ ){
cin >> c >> f >> v;
ff.push_back({c,f,v,1});
}
int m;
cin >> m;
for(int i = 0; i < m ; i ++ ){
cin >> c >> f >> v;
ff.push_back({c,f,v,2});
}
sort(ff.begin(),ff.end());
for(int i = 0 ; i < M; i ++ ){
dp[i]=-inf;
}
dp[0]=0;
int mx = 0;
ll ans = 0;
for(int i = ff.size() - 1; i >= 0 ; i -- ){
if(ff[i].type == 1){
for(int j = mx; j >= 0; j -- ){
dp[j+ff[i].cores]=max(dp[j+ff[i].cores],dp[j]-ff[i].val);
}
mx += ff[i].cores;
}
else{
for(int j = ff[i].cores; j <= mx ; j ++ ){
dp[j-ff[i].cores]=max(dp[j-ff[i].cores],dp[j]+ff[i].val);
ans = max(ans,dp[j-ff[i].cores]);
}
}
}
cout << ans << "\n";
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... |