// Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii; typedef pair<ll, ll> pll;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) begin(x),end(x)
template<typename I> bool chmax(I &a, I b){ return a < b ? ( a = b, true ) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? ( a = b, true ) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){cerr<<endl;}
template<class I, class...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<class I> void DE(I a, I b){ while(a < b) cerr<<*a<<" \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
const int N = 1e6 + 225;
int n, m;
ll a[N], b[N], s[N], t[N], p[N], q[N];
ll dp[N];
int bs(ll lft){
int ans = 0;
for(int l = 1<<30; l > 0; l >>= 1){
if(ans + l > m) continue;
if(b[ans + l] <= lft) ans += l;
}
return ans;
}
void solve1(){
FOO(i,1,n) a[i] += a[i-1];
FOO(i,1,n) p[i] += p[i-1];
FOO(i,1,m) b[i] += b[i-1];
FOO(i,1,m) q[i] += q[i-1];
ll ans = q[bs(s[1])];
FOO(i,1,n){
if(a[i] > s[1]) break;
ll left = s[1] - a[i];
chmax(ans, p[i] + q[bs(left)]);
}
cout << ans;
}
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
FOO(i,1,n) cin >> a[i] >> s[i] >> p[i];
FOO(i,1,m) cin >> b[i] >> t[i] >> q[i];
solve1();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
9836 KB |
Output is correct |
2 |
Correct |
188 ms |
9708 KB |
Output is correct |
3 |
Correct |
206 ms |
10092 KB |
Output is correct |
4 |
Correct |
198 ms |
10092 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
220 ms |
9708 KB |
Output is correct |
7 |
Correct |
84 ms |
5356 KB |
Output is correct |
8 |
Correct |
93 ms |
5356 KB |
Output is correct |
9 |
Correct |
187 ms |
10112 KB |
Output is correct |
10 |
Correct |
145 ms |
10220 KB |
Output is correct |
11 |
Correct |
140 ms |
10220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
9836 KB |
Output is correct |
2 |
Correct |
188 ms |
9708 KB |
Output is correct |
3 |
Correct |
206 ms |
10092 KB |
Output is correct |
4 |
Correct |
198 ms |
10092 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
220 ms |
9708 KB |
Output is correct |
7 |
Correct |
84 ms |
5356 KB |
Output is correct |
8 |
Correct |
93 ms |
5356 KB |
Output is correct |
9 |
Correct |
187 ms |
10112 KB |
Output is correct |
10 |
Correct |
145 ms |
10220 KB |
Output is correct |
11 |
Correct |
140 ms |
10220 KB |
Output is correct |
12 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
191 ms |
9836 KB |
Output is correct |
2 |
Correct |
188 ms |
9708 KB |
Output is correct |
3 |
Correct |
206 ms |
10092 KB |
Output is correct |
4 |
Correct |
198 ms |
10092 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
220 ms |
9708 KB |
Output is correct |
7 |
Correct |
84 ms |
5356 KB |
Output is correct |
8 |
Correct |
93 ms |
5356 KB |
Output is correct |
9 |
Correct |
187 ms |
10112 KB |
Output is correct |
10 |
Correct |
145 ms |
10220 KB |
Output is correct |
11 |
Correct |
140 ms |
10220 KB |
Output is correct |
12 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |