Submission #793475

#TimeUsernameProblemLanguageResultExecution timeMemory
793475MISM06Cloud Computing (CEOI18_clo)C++14
100 / 100
1163 ms7148 KiB
//0 1 1 0 1 //0 1 0 0 1 //1 0 0 1 1 //0 1 1 0 1 #include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") // #pragma GCC target("avx2") using namespace std; #define F first #define S second #define pb push_back #define sze size() #define all(x) x.begin() , x.end() #define wall__ cout << "--------------------------------------\n"; #define kids int mid = (tl + tr) >> 1, cl = v << 1, cr = v << 1 | 1 #define file_io freopen("input.cpp", "r", stdin); freopen("output.cpp", "w", stdout); typedef long long ll; typedef long double dl; typedef pair < int , int > pii; typedef pair < int , ll > pil; typedef pair < ll , int > pli; typedef pair < ll , ll > pll; typedef pair < int , pii > piii; typedef pair < ll, pll > plll; const ll N = 2000 + 10; const ll mod = 1e9 + 7; const ll inf = 2e16; const ll INF = 1e9 + 10; const ll lg = 32; ll dp[2][N][210], n, m, c1[N], f1[N], v1[N], c2[N], f2[N], v2[N]; vector < piii > o1, o2; void solve () { cin >> n; for (int i = 1; i <= n; i++) { int c, f, v; cin >> c >> f >> v; o1.pb({f, {c, v}}); } cin >> m; for (int i = 1; i <= m; i++) { int c, f, v; cin >> c >> f >> v; o2.pb({f, {c, v}}); } sort(all(o1)); sort(all(o2)); for (int i = 1; i <= n; i++) { f1[i] = o1[i - 1].F; c1[i] = o1[i - 1].S.F; v1[i] = o1[i - 1].S.S; } for (int i = 1; i <= m; i++) { f2[i] = o2[i - 1].F; c2[i] = o2[i - 1].S.F; v2[i] = o2[i - 1].S.S; } int t = 0; for (int i = 0; i <= n; i++) { t ^= 1; for (int j = 1; j <= m; j++) { for (int k = 0; k <= 100; k++) { dp[t][j][k] = 0; if (i == 0) { if (k >= c2[j]) dp[t][j][k] = max(dp[t][j - 1][k - c2[j]] + v2[j], dp[t][j][k]); dp[t][j][k] = max(dp[t][j][k], dp[t][j - 1][k]); } else { dp[t][j][k] = max({0ll, dp[t][j - 1][k], dp[t^1][j][k]}); if (f1[i] >= f2[j]) dp[t][j][k] = max(dp[t][j][k], dp[t^1][j][k + c1[i]] - v1[i]); if (k >= c2[j]) dp[t][j][k] = max(dp[t][j][k], dp[t][j - 1][k - c2[j]] + v2[j]); } } } } cout << dp[t][m][0] << '\n'; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; } /* */ //shrek is love;
#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...