이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define name "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ft first
#define se second
#define pii pair<int, int>
#define getbit(i, j) ((i >> j) & 1)
#define pb push_back
#define maxn 2003
using namespace std;
int n, m;
struct dl{
int c, f, v;
bool operator < (const dl &o) const {
if(f == o.f) return v > o.v;
return f < o.f;
}
}a[maxn], b[maxn];
int nc, mc, nv, mv, nf, mf;
ll res, dp[255][255];
void sub3(){
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
fi(i, 1, n){
fi(j, 1, m) if(a[i].f >= b[j].f){
int money = b[j].v - a[i].v;
if(money <= 0) continue;
// tinh dp[i][j] tu i - 1 hoac j - 1
fi(u, 0, i - 1) dp[i][j] = max(dp[i][j], dp[u][j - 1] + money);
fi(u, 0, j - 1) dp[i][j] = max(dp[i][j], dp[i - 1][u] + money);
// cap nhat len dp[i][u] & dp[u][j];
fi(u, j + 1, m) dp[i][u] = max(dp[i][u], dp[i][j]);
fi(u, i + 1, n) dp[u][i] = max(dp[u][j], dp[i][j]);
}
}
fi(i, 1, n)
fi(j, 1, m) res = max(res, dp[i][j]);
cout << res;
exit(0);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//freopen(name".in", "r", stdin);
// freopen(name".out", "w", stdout);
cin >> n;
fi(i, 1, n){
int c, f, v;
cin >> c >> f >> v;
a[i] = {c, f, v};
nc = max(nc, c);
nf = max(nf, f);
nv = max(nv, v);
}
cin >> m;
fi(i, 1, m){
int c, f, v;
cin >> c >> f >> v;
b[i] = {c, f, v};
mc = max(mc, c);
mf = max(mf, f);
mv = max(mv, v);
}
if(n <= 250 && m <= 250 && nc == 1 && mc == 1) sub3();
}
# | 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... |