This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//In the name of God
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MXN = 4e3 + 10;
const ll MXM = 2e5 + 10;
ll n, m; bool Tp[MXN];
ll M[MXN], F[MXN], T[MXN], Ind[MXN], dp[MXM];
void ckmx(ll &x, ll y){ x = max(x, y); }
int main(){
ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
cin >> n, iota(Ind + 1, Ind + MXN, 1);
for(int i = 1; i <= n; i ++) cin >> T[i] >> F[i] >> M[i]; cin >> m;
for(int i = 1; i <= m; i ++) cin >> T[i + n] >> F[i + n] >> M[i + n], Tp[i + n] = 1;
sort(Ind + 1, Ind + n + m + 1, [&](const int &i, const int &j){ return F[i] < F[j]; });
for(int ii = 1; ii <= n + m; ii ++){ int i = Ind[ii];
if(Tp[i]) for(int j = MXM - 1; j >= T[i]; -- j) ckmx(dp[j], dp[j - T[i]] + M[i]);
else for(int j = 0; j < MXM - T[i]; j ++) ckmx(dp[j], dp[j + T[i]] - M[i]);
} cout << dp[0] << '\n';
return 0;
}
//N.N
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:14:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
14 | for(int i = 1; i <= n; i ++) cin >> T[i] >> F[i] >> M[i]; cin >> m;
| ^~~
clo.cpp:14:60: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
14 | for(int i = 1; i <= n; i ++) cin >> T[i] >> F[i] >> M[i]; cin >> m;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |