Submission #246361

#TimeUsernameProblemLanguageResultExecution timeMemory
246361SortingCloud Computing (CEOI18_clo)C++14
100 / 100
710 ms2168 KiB
#include <bits/stdc++.h> using namespace std; const int k_N = 2000 + 3; const int k_C = 50; int n, m; array<int, 4> arr[2 * k_N];//f, which, c, v long long dp[2][k_N * k_C]; int sum_c; int main(){ ios::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 0; i < n; ++i){ cin >> arr[i][2] >> arr[i][0] >> arr[i][3]; arr[i][1] = 1; sum_c += arr[i][2]; } cin >> m; for(int i = 0; i < m; ++i){ cin >> arr[i + n][2] >> arr[i + n][0] >> arr[i + n][3]; arr[i + n][1] = 0; } sort(arr, arr + n + m); reverse(arr, arr + n + m); for(int i = 0; i <= sum_c; ++i) dp[(n + m) & 1][i] = 0; for(int i = n + m - 1; i >= 0; --i){ bool curr = i & 1; bool nxt = !curr; for(int j = 0; j <= sum_c; ++j){ long long &answer = dp[curr][j]; answer = dp[nxt][j]; if(arr[i][1]) answer = max(dp[nxt][j + arr[i][2]] - arr[i][3], answer); else if(j >= arr[i][2]) answer = max(dp[nxt][j - arr[i][2]] + arr[i][3], answer); } } cout << dp[0][0] << "\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...