This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define piii pair<int,pair<int,int>>
#define fi first
#define se second
const int N = 2e3 + 5;
const int inf = 0x3f3f3f3f3f3f3f3f;
vector<piii>vec;
vector<int>dp_before,dp_cur;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
int c,f,v;
cin >> c >> f >> v;
vec.push_back({f,{c,-v}});
}
int m;
cin >> m;
for (int i = 1; i <= m; i++) {
int c,f,v;
cin >> c >> f >> v;
vec.push_back({f,{-c,v}});
}
sort(vec.rbegin(),vec.rend());
dp_before.push_back(0);
for (int i = 0; i < (int)vec.size(); i++) {
dp_cur = dp_before;
for (int j = 0; j < dp_before.size(); j++) {
int newCnt = j + vec[i].se.fi,newCost = dp_before[j] + vec[i].se.se;
if (newCnt >= 0) {
while ((int)dp_cur.size() <= newCnt) dp_cur.push_back(-inf);
dp_cur[newCnt] = max(dp_cur[newCnt],newCost);
}
}
dp_before = dp_cur;
}
int ans = 0;
for (auto x: dp_before) ans = max(ans,x);
cout << ans << "\n";
}
Compilation message (stderr)
clo.cpp: In function 'int main()':
clo.cpp:35:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int j = 0; j < dp_before.size(); j++) {
| ~~^~~~~~~~~~~~~~~~~~
# | 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... |