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 N 2005
#define C 55
using namespace std;
void solve(){
int n;
cin >> n;
map<int,vector<pair<int,int>>> events;
int sum = 0;
for(int i = 1;i<=n;i++){
int c,f,v;
cin >> c >> f >> v;
sum += c;
events[-2*f - 1].push_back({c,v});
}
int m;
cin >> m;
for(int i = 1;i<=m;i++){
int c,f,v;
cin >> c >> f >> v;
events[-2*f].push_back({c,v});
}
vector<long long> dp(sum+1,-2e18);
dp[0] = 0;
int nowsum = 0;
for(auto c:events){
//cout << -c.first << endl;
for(auto u:c.second){
//cout << u.first << " " << u.second << endl;
int num = -c.first;
if(num % 2){
for(int i = nowsum;i>=0;i--){
dp[i+u.first] = max(dp[i+u.first],dp[i] - u.second);
}
nowsum += u.first;
}
else{
for(int i = 0;i<=nowsum;i++){
if(i+u.first > sum)break;
dp[i] = max(dp[i],dp[i+u.first] + u.second);
}
}
}
}
long long ans = 0;
for(int i = 0;i<=sum;i++){
ans = max(ans,dp[i]);
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while(t--){
solve();
}
#ifdef Local
cout << endl << fixed << setprecision(2) << 1000.0*clock()/CLOCKS_PER_SEC << " milliseconds";
#endif
}
# | 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... |