Submission #494172

#TimeUsernameProblemLanguageResultExecution timeMemory
494172radalCloud Computing (CEOI18_clo)C++14
100 / 100
1159 ms5316 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC target("avx2,fma") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef pair<int,int> pll; const long long int N = 2e3+20,mod = 1e9+7,inf = 1e18,sq = 400; inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; if (a+b < 0) return a+b+mod; return a+b; } inline int poww(int n,int k){ int c = 1; while (k){ if (k&1) c = (1ll*c*n)%mod; n = (1ll*n*n)%mod; k >>= 1; } return c; } int n,m; pair<int,pll> a[N],b[N]; ll dp[2][N][51][3]; int main(){ ios :: sync_with_stdio(0); cin.tie(0); cin >> n; rep(i,1,n+1) cin >> a[i].Y.X >> a[i].X >> a[i].Y.Y; cin >> m; rep(i,1,m+1) cin >> b[i].Y.X >> b[i].X >> b[i].Y.Y; sort(a+1,a+n+1); sort(b+1,b+m+1); rep(i,1,m+1){ rep(k,1,51){ dp[0][i][k][1] = -inf; } } rep(i,1,n+1){ int d1 = (i&1); rep(j,1,m+1){ //int d2 = (j&1); int u = a[i].Y.X,v = b[j].Y.X; dp[d1][j][u][2] = max(dp[1-d1][j][a[i-1].Y.X][2],dp[d1][j-1][u][2]); if (b[j].X <= a[i].X){ if (u < v){ dp[d1][j][u][2] = max(dp[d1][j][u][2],dp[1-d1][j][v-u][1]+b[j].Y.Y-a[i].Y.Y); } if (u == v){ dp[d1][j][u][2] = max(dp[d1][j][u][2],dp[1-d1][j-1][a[i-1].Y.X][2]+b[j].Y.Y-a[i].Y.Y); } if (u > v){ dp[d1][j][u][2] = max(dp[d1][j][u][2],dp[d1][j-1][u-v][0]+b[j].Y.Y-a[i].Y.Y); } } dp[d1][j][v][2] = dp[d1][j][u][2]; rep(k,1,u){ dp[d1][j][k][0] = dp[d1][j-1][k][0]; if (b[j].X <= a[i].X){ if (b[j].Y.X > k){ dp[d1][j][k][0] = max(dp[d1][j][k][0],dp[1-d1][j][b[j].Y.X-k][1]+b[j].Y.Y); } if (b[j].Y.X == k){ dp[d1][j][k][0] = max(dp[d1][j][k][0],dp[1-d1][j-1][a[i-1].Y.X][2]+b[j].Y.Y); } if (k > b[j].Y.X){ dp[d1][j][k][0] = max(dp[d1][j][k][0],dp[d1][j-1][k-b[j].Y.X][0]+b[j].Y.Y); } } } rep(k,1,v){ dp[d1][j][k][1] = dp[1-d1][j][k][1]; if (b[j].X <= a[i].X){ if (a[i].Y.X > k){ dp[d1][j][k][1] = max(dp[d1][j][k][1],dp[d1][j-1][a[i].Y.X-k][0]-a[i].Y.Y); } if (a[i].Y.X == k){ dp[d1][j][k][1] = max(dp[d1][j][k][1],dp[1-d1][j-1][a[i-1].Y.X][2]-a[i].Y.Y); } if (k > a[i].Y.X){ dp[d1][j][k][1] = max(dp[d1][j][k][1],dp[1-d1][j][k-a[i].Y.X][1]-a[i].Y.Y); } } } } } cout << dp[(n&1)][m][a[n].Y.X][2]; }
#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...