#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 1000010, MAX_M = 2005;
const ll inf = 1ll << 59;
int n, m;
ll a[MAX_N], s[MAX_N], p[MAX_N], c[MAX_N];
ll b[MAX_N], t[MAX_N], q[MAX_N], d[MAX_N];
ll dp[MAX_M][MAX_M];
bool ok[MAX_N];
ll dp_diff[MAX_N];
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;++i) cin >> a[i] >> s[i] >> p[i];
for (int i = 1;i <= m;++i) cin >> b[i] >> t[i] >> q[i];
for (int i = 1;i <= n;++i) a[i] += a[i-1];
for (int i = 1;i <= m;++i) b[i] += b[i-1];
for (int i = 1;i <= n;++i)
c[i] = upper_bound(b, b + m + 1, s[i] - a[i]) - b - 1;
for (int i = 1;i <= m;++i)
d[i] = upper_bound(a, a + n + 1, t[i] - b[i]) - a - 1;
dp_diff[0] = 0;
for (int i = 1;i <= m;++i) dp_diff[0] += q[i];
for (int i = 1;i <= m;++i) {
dp_diff[i] = (0 > d[i] ? -q[i] : 0);
}
debug(dp_diff, dp_diff + m + 1);
vector<int> id(m); iota(AI(id), 1);
sort(AI(id), [&](int x, int y) {
return d[x] < d[y];
});
for (int i = 0, j = 0;i < n;++i) {
// first transfer i+1
int v = c[i+1];
dp_diff[0] += p[i+1];
dp_diff[v+1] -= p[i+1];
auto upd = [&](int j) {
chmax(dp_diff[j], (i > d[j] ? -q[j] : 0));
};
// while (j < m && i > d[ id[j] ]) {
// ok[ id[j] ] = true;
// upd(id[j++]);
// }
//upd(v+1);
for (int j = 1;j <= m;++j) upd(j);
//debug(dp_diff, dp_diff + m + 1);
}
ll res = 0;
for (int i = 0;i <= m;++i) res += dp_diff[i];
cout << res << '\n';
//
// for (int i = 0;i <= n;++i) for (int j = 0;j <= m;++j)
// dp[i][j] = -inf;
//
// dp[0][0] = 0;
// for (int j = 1;j <= m;++j) dp[0][0] += q[j];
//
// for (int i = 0;i <= n;++i) {
// for (int j = 0;j <= m;++j) {
// // done
// // equals to for j in [0, c[i+1]], dp[i][j] += p[i+1];
// //
//
// //chmax(dp[i][j+1], dp[i][j] + (i > d[j+1] ? -q[j+1] : 0));
// if (j) chmax(dp[i][j], dp[i][j-1] + (i > d[j] ? -q[j] : 0));
//
// chmax(dp[i+1][j], dp[i][j] + (j <= c[i+1] ? p[i+1] : 0));
// DE(i, j, dp[i][j]);
// }
// }
//
// cout << dp[n][m] << '\n';
}
Compilation message
dishes.cpp: In function 'int32_t main()':
dishes.cpp:15:20: warning: statement has no effect [-Wunused-value]
15 | #define debug(...) 0
| ^
dishes.cpp:50:2: note: in expansion of macro 'debug'
50 | debug(dp_diff, dp_diff + m + 1);
| ^~~~~
dishes.cpp:57:18: warning: unused variable 'j' [-Wunused-variable]
57 | for (int i = 0, j = 0;i < n;++i) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10004 ms |
15236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10004 ms |
15236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10004 ms |
15236 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |