Submission #361727

#TimeUsernameProblemLanguageResultExecution timeMemory
361727knightron0Cloud Computing (CEOI18_clo)C++14
100 / 100
565 ms2412 KiB
#include <bits/stdc++.h> #pragma GCC optimize("02") using namespace std; #define pb push_back #define fr first #define sc second #define clr(a, x) memset(a, x, sizeof(a)) #define dbg(x) cout<<"("<<#x<<"): "<<x<<endl; #define printvector(arr) for (auto it = arr.begin(); it != arr.end(); ++it) cout<<*it<<" "; cout<<endl; #define all(v) v.begin(), v.end() #define lcm(a, b) (a * b)/__gcd(a, b) #define int long long int #define printvecpairs(vec) for(auto it: vec) cout<<it.fr<<' '<<it.sc<<endl; #define endl '\n' #define float long double const int MOD = 1e9 + 7; const int INF = 2e15; const int MAXN = 900; vector<pair<pair<int, int>, pair<int,int>>> vec; bool compare(pair<pair<int, int>, pair<int,int>> p1, pair<pair<int, int>, pair<int,int>> p2){ if(p1.fr.fr == p2.fr.fr){ if(p1.fr.sc == p2.fr.sc){ return p1.sc.sc < p1.sc.sc; } else { return p1.fr.sc < p2.fr.sc; } } else { return p1.fr.fr > p2.fr.fr; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); #ifdef LOCAL freopen("input.txt", "r", stdin); #endif int n; cin>>n; int mx = 0; for(int i= 0;i<n;i++){ int t1, t2, t3; cin>>t1>>t2>>t3; vec.pb({{t2, -1},{t1, t3}}); mx = max(mx, t1); } int m; cin>>m; for(int i= 0;i<m;i++){ int t1, t2, t3; cin>>t1>>t2>>t3; vec.pb({{t2, 1},{t1, t3}}); mx = max(mx, t1); } int nm = n+m; int mk = mx*n; sort(all(vec), compare); int dp[2][mk+5]; for(int i= 1;i<=mk;i++) dp[0][i] = -INF; dp[0][0] = 0; for(int i= 1;i<=nm;i++){ int par = i%2; for(int j= 0;j<=mk;j++){ if(vec[i-1].fr.sc == 1){ if(j + vec[i-1].sc.fr <= mk){ dp[par][j] = max(dp[par^1][j+vec[i-1].sc.fr] + vec[i-1].sc.sc, dp[par^1][j]); } else { dp[par][j] = dp[par^1][j]; } } else { if(j >= vec[i-1].sc.fr){ dp[par][j] = max(dp[par^1][j-vec[i-1].sc.fr]-vec[i-1].sc.sc, dp[par^1][j]); } else { dp[par][j] = dp[par^1][j]; } } } } int ans = 0; for(int j=0;j<=mk;j++){ ans = max(ans, dp[(nm%2)][j]); } cout<<ans<<endl; return 0; }

Compilation message (stderr)

clo.cpp: In function 'bool compare(std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >, std::pair<std::pair<long long int, long long int>, std::pair<long long int, long long int> >)':
clo.cpp:27:29: warning: self-comparison always evaluates to false [-Wtautological-compare]
   27 |             return p1.sc.sc < p1.sc.sc;
      |                             ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...