이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = a; i < b; i++)
#define pb push_back
#define INF 1e18
typedef vector<int> vi;
typedef long long ll;
struct comp {
int cost, cores, speed;
comp(int cst, int crs, int s) {cost = cst; cores = crs; speed = s;}
comp() {};
};
int n, m;
int MAXCORES = 50 * 2000 + 100;
int main()
{
cin >> n;
vector<comp> store(n);
rep(i,0,n) cin >> store[i].cores >> store[i].speed >> store[i].cost;
cin >> m;
vector<comp> customer(m);
rep(i,0,m) cin >> customer[i].cores >> customer[i].speed >> customer[i].cost;
sort(store.begin(), store.end(), [](comp a, comp b) {
return ((float)a.cores / (float)a.cost > (float)b.cores / (float)b.cost);
});
vector<vector<ll>> kns(2, vector<ll>(MAXCORES, INF));
kns[0][store[0].cores] = store[0].cost;
kns[0][0] = 0;
rep(i,1,n) {
rep(c, 0, store[i].cores) {
kns[i&1][c] = kns[(i&1)^1][c];
}
rep(c, store[i].cores, MAXCORES) {
kns[i&1][c] = min(kns[(i&1)^1][c], kns[(i&1)^1][c - store[i].cores] + store[i].cost);
}
}
sort(customer.begin(), customer.end(), [](comp b, comp a) {
return ((float)a.cores / (float)a.cost > (float)b.cores / (float)b.cost);
});
vector<vector<ll>> knc(2, vector<ll>(MAXCORES, -INF));
knc[0][customer[0].cores] = customer[0].cost;
knc[0][0] = 0;
rep(i,1,m) {
rep(c, 0, customer[i].cores) {
knc[i&1][c] = knc[(i&1)^1][c];
}
rep(c, customer[i].cores, MAXCORES) {
knc[i&1][c] = max(knc[(i&1)^1][c], knc[(i&1)^1][c - customer[i].cores] + customer[i].cost);
}
}
for (int i = MAXCORES - 2; i; i--) kns[(n&1)^1][i] = min(kns[(n&1)^1][i], kns[(n&1)^1][i + 1]);
ll ans = 0;
rep(i, 0, MAXCORES) {
ans = max(ans, knc[(m&1)^1][i] - kns[(n&1)^1][i]);
}
cout << ans;
}
# | 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... |