#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2006;
const int mod = 1e9 + 7;
using lint = long long;
using pi = pair<int, int>;
struct pnt{
int x, y;
lint c;
bool operator<(const pnt &p)const{
return pi(x, y) < pi(p.x, p.y);
}
};
int n, m;
lint a[MAXN], s[MAXN], p[MAXN];
lint b[MAXN], t[MAXN], q[MAXN];
int da[MAXN], db[MAXN];
lint dp[MAXN];
vector<pnt> v, w;
lint getCostV(int s, int e, int y){
lint ret = 0;
for(int i=s; i<=e; i++){
if(v[i].y >= y) ret += v[i].c;
}
return ret;
}
lint getCostW(int x, int s, int e){
lint ret = 0;
for(auto &i : w){
if(i.x >= x && s <= i.y && i.y <= e) ret += i.c;
}
return ret;
}
int main(){
scanf("%d %d",&n,&m);
if(1ll * n * m > 4000000) return 0; //continue;
for(int i=1; i<=n; i++){
scanf("%lld %lld %lld",&a[i],&s[i],&p[i]);
a[i] += a[i-1];
}
for(int i=1; i<=m; i++){
scanf("%lld %lld %lld",&b[i],&t[i],&q[i]);
b[i] += b[i-1];
}
lint ret = 0;
v.push_back({0, 0, 0});
for(int i=1; i<=n; i++){
da[i] = upper_bound(b, b + m + 1, s[i] - a[i]) - b;
if(da[i] > 0){
if(p[i] > 0) v.push_back({i, da[i], p[i]});
else w.push_back({i, da[i], -p[i]}), ret += p[i];
}
}
for(int i=1; i<=m; i++){
db[i] = upper_bound(a, a + n + 1, t[i] - b[i]) - a;
if(db[i] > 0){
if(q[i] > 0) w.push_back({db[i], i, q[i]});
else v.push_back({db[i], i, -q[i]}), ret += q[i];
}
}
sort(v.begin(), v.end());
sort(w.begin(), w.end());
v.push_back({n + 1, m + 1, 0});
for(int i=1; i<v.size(); i++){
dp[i] = -1e18;
for(int j=0; j<i; j++){
if(v[j].y <= v[i].y){
dp[i] = max(dp[i],
dp[j]
+ getCostV(j + 1, i, v[i].y)
+ getCostW(v[j].x + 1, v[j].y, v[i].y - 1));
}
}
}
cout << ret + dp[v.size() - 1] << endl;
}
Compilation message
dishes.cpp: In function 'int main()':
dishes.cpp:69:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=1; i<v.size(); i++){
~^~~~~~~~~
dishes.cpp:40: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:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&a[i],&s[i],&p[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:47:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld",&b[i],&t[i],&q[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2686 ms |
644 KB |
Output is correct |
18 |
Correct |
1047 ms |
764 KB |
Output is correct |
19 |
Correct |
7825 ms |
680 KB |
Output is correct |
20 |
Correct |
844 ms |
748 KB |
Output is correct |
21 |
Correct |
7041 ms |
676 KB |
Output is correct |
22 |
Correct |
8058 ms |
632 KB |
Output is correct |
23 |
Correct |
7684 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2686 ms |
644 KB |
Output is correct |
18 |
Correct |
1047 ms |
764 KB |
Output is correct |
19 |
Correct |
7825 ms |
680 KB |
Output is correct |
20 |
Correct |
844 ms |
748 KB |
Output is correct |
21 |
Correct |
7041 ms |
676 KB |
Output is correct |
22 |
Correct |
8058 ms |
632 KB |
Output is correct |
23 |
Correct |
7684 ms |
748 KB |
Output is correct |
24 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2686 ms |
644 KB |
Output is correct |
18 |
Correct |
1047 ms |
764 KB |
Output is correct |
19 |
Correct |
7825 ms |
680 KB |
Output is correct |
20 |
Correct |
844 ms |
748 KB |
Output is correct |
21 |
Correct |
7041 ms |
676 KB |
Output is correct |
22 |
Correct |
8058 ms |
632 KB |
Output is correct |
23 |
Correct |
7684 ms |
748 KB |
Output is correct |
24 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
380 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
308 KB |
Output is correct |
11 |
Correct |
2 ms |
424 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2686 ms |
644 KB |
Output is correct |
18 |
Correct |
1047 ms |
764 KB |
Output is correct |
19 |
Correct |
7825 ms |
680 KB |
Output is correct |
20 |
Correct |
844 ms |
748 KB |
Output is correct |
21 |
Correct |
7041 ms |
676 KB |
Output is correct |
22 |
Correct |
8058 ms |
632 KB |
Output is correct |
23 |
Correct |
7684 ms |
748 KB |
Output is correct |
24 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |