이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAXN 2010
#define INF 1000000000000000000LL
using namespace std;
struct data
{
long long c;
long long f;
long long v;
};
data a[2*MAXN];
bool cmp(data x, data y)
{
return x.f > y.f;
}
long long prevNiz[100*MAXN];
long long tr[100*MAXN];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cerr.tie(0);
int n;
cin >> n;
int i = 0;
long long C = 0;
for(i = 0; i < n; i++)
{
cin >> a[i].c >> a[i].f >> a[i].v;
C += a[i].c;
a[i].v = -a[i].v;
}
int m;
cin >> m;
for(; i < n + m; i++)
{
cin >> a[i].c >> a[i].f >> a[i].v;
C += a[i].c;
a[i].c = -a[i].c;
}
for(int i = 0; i <= C; i++)
{
prevNiz[i] = -INF;
}
prevNiz[0] = 0;
//cout << "CHECKPOINT 1" << endl;
sort(a, a + m + n, cmp);
for(int i = 0; i < n + m; i++)
{
//cout << "START" << endl;
for(int j = 0; j <= C; j++)
{
//cout << "START 2" << endl;
tr[j] = prevNiz[j];
if(j - a[i].c >= 0 && j - a[i].c <= C && prevNiz[j - a[i].c] + a[i].v > tr[j])
{
tr[j] = prevNiz[j - a[i].c] + a[i].v;
}
//cout << "END 2" << endl;
}
//cout << "MID" << endl;
for(int j = 0; j <= C; j++)
{
prevNiz[j] = tr[j];
}
//cout << "END" << endl;
}
//cout << "CHECKPOINT 2" << endl;
long long res = 0;
for(int i = 0; i <= C; i++)
{
res = max(res, prevNiz[i]);
}
cout << res << endl;
return 0;
}
# | 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... |