이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// ~Be name khoda~ //
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define fi first
#define se second
#define cl clear
#define endll '\n'
const int maxn = 1e6 + 10;
const int maxn5 = 2e3 + 5;
const int maxnt = 1.2e6 + 10;
const int maxn3 = 1e3 + 10;
const int mod = 1e9 + 7;
const ll inf = 1e18;
ll dp[2][maxn5][2][52];
int f[maxn5], c[maxn5], v[maxn5];
int F[maxn5], C[maxn5], V[maxn5];
int pero[maxn5], perc[maxn5];
inline bool cmpc(int a, int b){return f[a] < f[b];}
inline bool cmpo(int a, int b){return F[a] < F[b];}
int main()
{
int n, m;
scanf("%d", &n);
for(int i = 1; i <= n; i++) scanf("%d%d%d", &c[i], &f[i], &v[i]);
scanf("%d", &m);
for(int i = 1; i <= m; i++) scanf("%d%d%d", &C[i], &F[i], &V[i]);
for(int i = 1; i <= n; i++) perc[i] = i;
for(int i = 1; i <= m; i++) pero[i] = i;
sort(perc + 1, perc + n + 1, cmpc);
sort(pero + 1, pero + m + 1, cmpo);
for(int i = 1; i <= m; i++){
int now = i%2;
int last = now ^ 1;
for(int ty = 0; ty < 2; ty++) for(int rem = 0; rem < 50; rem++){
if(rem == 0 || ty == 1) dp[now][0][ty][rem] = 0;
else dp[now][0][ty][rem] = -1 * inf;
}
for(int j = 1; j <= n; j++) for(int ty = 0; ty < 2; ty++) for(int rem = 0; rem < 50; rem++){
ll ans = -1 * inf;
if(rem == 0){
ans = 0;
ans = max(ans, dp[last][j][ty][0]);
ans = max(ans, dp[now][j - 1][ty][0]);
if(F[pero[i]] <= f[perc[j]]){
if(C[pero[i]] > c[perc[j]]){
ans = max(ans, ll(V[pero[i]]) - v[perc[j]] + dp[now][j - 1][0][C[pero[i]] - c[perc[j]]]);
}
else if(C[pero[i]] < c[perc[j]]){
ans = max(ans, ll(V[pero[i]]) - v[perc[j]] + dp[last][j][1][c[perc[j]] - C[pero[i]]]);
}
else{
ans = max(ans, ll(V[pero[i]]) - v[perc[j]] + dp[last][j - 1][0][0]);
}
}
}
else if(ty == 0){
ans = max(ans, dp[now][j - 1][ty][rem]);
if(F[pero[i]] <= f[perc[j]]){
if(rem > c[perc[j]]){
ans = max(ans, dp[now][j - 1][0][rem - c[perc[j]]] - v[perc[j]]);
}
else if(rem < c[perc[j]]){
ans = max(ans, dp[last][j][1][c[perc[j]] - rem] - v[perc[j]]);
}
else{
ans = max(ans, dp[last][j - 1][0][0] - v[perc[j]]);
}
}
}
else if(ty == 1){
ans = max(ans, dp[now][j - 1][0][0]);
ans = max(ans, dp[last][j][1][rem]);
if(F[pero[i]] <= f[perc[j]]){
if(C[pero[i]] > rem){
ans = max(ans, V[pero[i]] + dp[now][j - 1][0][C[pero[i]] - rem]);
}
else if(C[pero[i]] < rem){
ans = max(ans, V[pero[i]] + dp[last][j][1][rem - C[pero[i]]]);
}
else{
ans = max(ans, V[pero[i]] + dp[last][j - 1][0][0]);
}
}
}
dp[now][j][ty][rem] = ans;
}
}
cout << dp[m%2][n][0][0] << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
clo.cpp: In function 'int main()':
clo.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
clo.cpp:37:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | for(int i = 1; i <= n; i++) scanf("%d%d%d", &c[i], &f[i], &v[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clo.cpp:38:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &m);
| ~~~~~^~~~~~~~~~
clo.cpp:39:35: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | for(int i = 1; i <= m; i++) scanf("%d%d%d", &C[i], &F[i], &V[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |