Submission #1159252

#TimeUsernameProblemLanguageResultExecution timeMemory
1159252MPGCloud Computing (CEOI18_clo)C++20
100 / 100
418 ms2272 KiB
//#pragma GCC optomize("Ofast") #pragma GCC optimize("unroll-loops") //#pragma GCC optimize("O3") //#pragma GCC target("avx2") //#pragma GCC target("sse,sse2,sse4.1,sse4.2") #include <bits/stdc++.h> using namespace std; typedef long long ll; #define max_heap priority_queue<pair <ll, pair <ll, ll>>> #define min_heap priority_queue<pair <ll, ll>, vector<pair <ll, ll>>, greater<pair <ll, ll>>> //#define min_heap priority_queue<ll, vector<ll>, greater<ll>> #define sariE cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(false); #define filE freopen("in.txt", "r", stdin); freopen("out1.txt", "w", stdout); #define endl '\n' #define md(a) (a % mod + mod) % mod #define pb push_back //cout << vectorprecision(5) << fixed << f; //hash prime = 769 mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); ll const maxn = 2e5 + 123; ll const inf = 2e18; ll const loG = 23; ll const mod = 1e9 + 7; //ll const mod = 998244353; ll const sq = 400; ll power(ll a, ll b, ll mod){if(b==0)return 1;if(b==1)return a;ll x = power(a, b / 2, mod);return (((x * x) % mod) * (b % 2 ? a : 1)) % mod;} struct comp{ ll c, v, f; }; vector <comp> A; bool cmp(comp a, comp b){ if (a.f == b.f){ return a.c > b.f; } return a.f > b.f; } ll n, m, dp[2][100100]; void Solve(){ cin >> n; for (int i = 1; i < n + 1; i++){ comp tmp; cin >> tmp.c >> tmp.f >> tmp.v; tmp.v = -tmp.v; A.pb(tmp); } cin >> m; for (int i = 1; i < m + 1; i++){ comp tmp; cin >> tmp.c >> tmp.f >> tmp.v; tmp.c = -tmp.c; A.pb(tmp); } sort(A.begin(), A.end(), cmp); for (int i = 1; i < 100100; i++){ dp[0][i] = -inf; dp[1][i] = -inf; } dp[0][0] = 0; dp[1][0] = 0; ll cnt = 1; // for (auto p : A) // cout << p.c << ' ' << p.f << ' ' << p.v << endl; for (auto p : A){ ll gabl = cnt % 2; cnt++; ll now = cnt % 2; //cout << now << " " << gabl << endl; for (int k = 0; k < 100100; k++){ if ((p.c + k >= 0) && (p.c + k < 100100)){ dp[now][p.c + k] = max(dp[now][p.c + k], dp[gabl][k] + p.v); //cout << cnt - 1 << ' ' << dp[now][p.c + k] << ' ' << p.v << endl; } } for (int k = 0; k < 100100; k++) dp[gabl][k] = dp[now][k]; } ll ans = 0; for (int i = 0; i < 100100; i++) ans = max(ans, dp[cnt % 2][i]); cout << ans << endl; } int main(){ sariE;// filE; int test = 1; //cin >> test; while (test--) Solve(); return 0; }
#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...