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;
struct val
{
int c, f, v;
};
bool comp(val a, val b)
{
return a.f > b.f;
}
long long dp[100001];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n;
vector<val> com(n);
for(int i = 0; i < n; i++) cin >> com[i].c >> com[i].f >> com[i].v;
cin >> m;
vector<val> ord(m);
for(int i = 0; i < m; i++) cin >> ord[i].c >> ord[i].f >> ord[i].v;
sort(com.begin(), com.end(), comp);
sort(ord.begin(), ord.end(), comp);
fill(dp, dp + 100001, 1e18);
dp[0] = 0;
int l = 0;
while(l < m && ord[l].f > com[0].f) l++;
for(auto x : com)
{
while(l < m && ord[l].f > x.f)
{
val u = ord[l++];
for(int i = 0; i <= 100000 - u.c; i++)
{
dp[i] = min(dp[i], dp[i + u.c] - u.v);
}
}
for(int i = 100000; i >= 0; i--)
{
dp[i] = min(dp[i], dp[max(i - x.c, 0)] + x.v);
}
}
while(l < m)
{
val u = ord[l++];
for(int i = 0; i <= 100000 - u.c; i++)
{
dp[i] = min(dp[i], dp[i + u.c] - u.v);
}
}
cout << dp[0] * -1;
}
# | 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... |