#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 2e3 + 50;
const ll INF = 1e18;
ll del[N], mora[N], dp[N][N], S[N], T[N];
int n, m, bio[N][N];
int Q[N], P[N], A[N], B[N];
int SS[N], TT[N];
vector < ll > v, v2;
vector < int > brisi[N];
ll f(int x, int y){
if(x == 0 && y == 0) return 0;
if(bio[x][y]) return dp[x][y];
ll ret = -INF;
if(x)
ret = max(ret, f(x - 1, y) + (y <= SS[x] ? P[x] : 0));
if(y)
ret = max(ret, f(x, y - 1) + (x <= TT[y] ? Q[y] : 0));
bio[x][y] = 1; dp[x][y] = ret;
return dp[x][y];
}
int main(){
scanf("%d%d", &n, &m);
for(int i = 1;i <= n;i++)
scanf("%d%lld%d", A + i, S + i, P + i);
for(int i = 1;i <= m;i++)
scanf("%d%lld%d", B + i, T + i, Q + i);
ll cur = 0; v.PB(cur);
for(int i = 1;i <= m;i++)
cur += B[i], v.PB(cur);
cur = 0; v2.PB(cur);
for(int i = 1;i <= n;i++){
cur += A[i]; v2.PB(cur);
if(S[i] < cur)
P[i] = 0, S[i] = cur;
SS[i] = upper_bound(v.begin(), v.end(), S[i] - cur) - v.begin() - 1;
}
cur = 0;
for(int i = 1;i <= m;i++){
cur += B[i];
if(T[i] < cur)
Q[i] = 0, T[i] = cur;
TT[i] = upper_bound(v2.begin(), v2.end(), T[i] - cur) - v2.begin() - 1;
}
for(int i = 1;i <= m;i++){
del[i] = Q[i], mora[i] = Q[i];
brisi[TT[i]].PB(i);
}
cur = 0;
//for(int i = 1;i <= n;i++)
// printf("S[ %d ] = %d P[ %d ] = %d\n", i, SS[i], i, P[i]);
//for(int i = 1;i <= m;i++)
// printf("T[ %d ] = %d Q[ %d ] = %d\n", i, TT[i], i, Q[i]);
//for(int j = 0;j <= m;j++){
// cur += del[j];
// printf("%lld ", cur);
// if(j == m) printf("\n");
//}
for(int i = 1;i <= n;i++){
del[0] += P[i];
del[SS[i] + 1] -= P[i];
int sad = SS[i] + 1;
while(sad <= m && del[sad] < mora[sad]){
del[sad + 1] -= mora[sad] - del[sad];
del[sad] = mora[sad]; sad++;
}
for(int j : brisi[i])
mora[j] = 0;
//ll cur = 0;
//for(int j = 0;j <= m;j++){
// cur += del[j];
// printf("%lld ", cur);
// if(j == m) printf("\n");
//}
//for(int j = 0;j <= m;j++){
// printf("%lld ", del[j]);
// if(j == m) printf("\n");
//}
}
//printf("----------\n");
//for(int i = 0;i <= n;i++){
// for(int j = 0;j <= m;j++)
// printf("%lld ", f(i, j));
// printf("\n");
//}
ll ans = 0;
for(int i = 0;i <= m;i++)
ans += del[i];
printf("%lld\n", ans);
}
Compilation message
dishes.cpp: In function 'int main()':
dishes.cpp:35:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%lld%d", A + i, S + i, P + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%lld%d", B + i, T + i, Q + i);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
230 ms |
12136 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
230 ms |
12136 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
230 ms |
12136 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |