제출 #729577

#제출 시각아이디문제언어결과실행 시간메모리
729577dozerCloud Computing (CEOI18_clo)C++14
100 / 100
1962 ms3688 KiB
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; #define sp " " #define endl "\n" #define fastio() cin.tie(0), ios_base::sync_with_stdio(0) #define pii pair<int, int> #define st first #define nd second #define pb push_back #define N 2005 #define L(node) node * 2 #define R(node) node * 2 + 1 #define int long long #define M 51 int dp[2][N][M][2]; array<int, 3> cust[N], comp[N]; const int INF = 2e18 + 7; int32_t main() { fastio(); int n; cin>>n; for (int i = 1; i <= n; i++) cin>>comp[i][1]>>comp[i][0]>>comp[i][2]; int m; cin>>m; for (int i = 1; i <= m; i++) cin>>cust[i][1]>>cust[i][0]>>cust[i][2]; sort(comp + 1, comp + 1 + n); sort(cust + 1, cust + 1 + m); for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { for (int l = 1; l >= 0; l--) { for (int k = 0; k < M; k++) { int t1 = -INF, t2 = -INF, t3 = -INF, t4 = -INF; t1 = dp[1][j - 1][k][l]; t3 = dp[0][j][k][0]; if (l == 0 && k + comp[i][1] >= cust[j][1] && k + comp[i][1] - cust[j][1] < M && comp[i][0] >= cust[j][0]) t2 = dp[1][j - 1][k + comp[i][1] - cust[j][1]][1] - comp[i][2] + cust[j][2]; if (l == 0 && k + comp[i][1] < M) t2 = max(t2, dp[1][j][k + comp[i][1]][1] - comp[i][2]); if (k >= cust[j][1] && comp[i][0] >= cust[j][0]) t4 = dp[1][j - 1][k - cust[j][1]][l] + cust[j][2]; int ans = max(t1, t2); ans = max(ans, t3); ans = max(ans, t4); dp[1][j][k][l] = ans; } } } for (int j = 1; j <= m; j++) { for (int l = 1; l >=0; l--) { for (int k = 0; k < M; k++) dp[0][j][k][l] = dp[1][j][k][l]; } } } cout<<dp[0][m][0][0]<<endl; cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n"; }
#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...