#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pip pair<int, pii>
#define ppi pair<pii, int>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const double PI=acos(-1);
const ll maxn = 1e6+5;
const ll maxm = 3e3+5;
const ll inf = 1ll<<60;
const ll mod = 998244353;
ll pw(ll a, ll p){
ll ret = 1;
while(p > 0){
if (p&1){
ret *= a;
ret %= mod;
}
a *= a;
a %= mod;
p >>= 1;
}
return ret;
}
ll inv(ll a){
return pw(a, mod-2);
}
int n, m;
vector<pip> v;
vector<pip> ina(maxn), inb(maxn);
bool cmp(pip a, pip b){
if (a.f == b.f){
return a.s.f > b.s.f;
}
return a.f < b.f;
}
signed main(){
IOS();
cin>>n>>m;
vector<int> pfa(n+1), pfb(m+1);
REP1(i, n){
cin>>ina[i].f>>ina[i].s.f>>ina[i].s.s;
pfa[i] = pfa[i-1] + ina[i].f;
}
REP1(i, m){
cin>>inb[i].f>>inb[i].s.f>>inb[i].s.s;
pfb[i] = pfb[i-1] + inb[i].f;
}
REP1(i, n){
int dd = upper_bound(ALL(pfb), ina[i].s.f - pfa[i])-pfb.begin()-1;
if (dd >= 0) v.pb({i, {dd, ina[i].s.s}});
}
int jsum = 0;
REP1(i, m){
int dd = upper_bound(ALL(pfa), inb[i].s.f - pfb[i])-pfa.begin()-1;
if (dd >= 0){
jsum += inb[i].s.s;
if (dd < n) v.pb({dd+1, {i-1, -inb[i].s.s}});
}
}
sort(ALL(v), cmp);
vector<pip> vv;
REP(i, SZ(v)){
if (vv.empty() || vv.back().f != v[i].f || vv.back().s.f != v[i].s.f) vv.pb(v[i]);
else vv[SZ(vv)-1].s.s += v[i].s.s;
}
/*map<int, int> mp;
mp[0] = 0;
for (auto p:v){
pii ac = p.s;
mp[0] += ac.s;
if (ac.s < 0){
if (ac.f < m) mp[ac.f+1] += -ac.s;
}
else {
auto it = mp.upper_bound(ac.f);
int rem = ac.s;
while (it != mp.end() && (*it).s <= rem){
rem -= (*it).s;
it = mp.erase(it);
}
if (it != mp.end()){
mp[(*it).f] = (*it).s - rem;
}
}
}
int ans = 0;
for (auto v:mp) ans += v.s;
cout<<ans+jsum<<endl;
*/
// testing
vector<int> dp(m+1);
for(auto p:vv){
REP(i, m+1){
if (i <= p.s.f) dp[i] += p.s.s;
if (i > 0) dp[i] = max(dp[i], dp[i-1]);
}
}
cout<<dp[m]+jsum<<endl;
}
// funny euler tour :)
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10038 ms |
84132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
47448 KB |
Output is correct |
2 |
Correct |
12 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47192 KB |
Output is correct |
5 |
Correct |
12 ms |
47244 KB |
Output is correct |
6 |
Correct |
11 ms |
47196 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
10 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47216 KB |
Output is correct |
11 |
Correct |
11 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
16 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47196 KB |
Output is correct |
15 |
Correct |
12 ms |
47224 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
47448 KB |
Output is correct |
2 |
Correct |
12 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47192 KB |
Output is correct |
5 |
Correct |
12 ms |
47244 KB |
Output is correct |
6 |
Correct |
11 ms |
47196 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
10 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47216 KB |
Output is correct |
11 |
Correct |
11 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
16 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47196 KB |
Output is correct |
15 |
Correct |
12 ms |
47224 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
16 ms |
47572 KB |
Output is correct |
18 |
Correct |
19 ms |
47708 KB |
Output is correct |
19 |
Correct |
22 ms |
47652 KB |
Output is correct |
20 |
Correct |
17 ms |
47452 KB |
Output is correct |
21 |
Correct |
20 ms |
47712 KB |
Output is correct |
22 |
Correct |
21 ms |
47708 KB |
Output is correct |
23 |
Correct |
20 ms |
47800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
47448 KB |
Output is correct |
2 |
Correct |
12 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47192 KB |
Output is correct |
5 |
Correct |
12 ms |
47244 KB |
Output is correct |
6 |
Correct |
11 ms |
47196 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
10 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47216 KB |
Output is correct |
11 |
Correct |
11 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
16 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47196 KB |
Output is correct |
15 |
Correct |
12 ms |
47224 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
16 ms |
47572 KB |
Output is correct |
18 |
Correct |
19 ms |
47708 KB |
Output is correct |
19 |
Correct |
22 ms |
47652 KB |
Output is correct |
20 |
Correct |
17 ms |
47452 KB |
Output is correct |
21 |
Correct |
20 ms |
47712 KB |
Output is correct |
22 |
Correct |
21 ms |
47708 KB |
Output is correct |
23 |
Correct |
20 ms |
47800 KB |
Output is correct |
24 |
Execution timed out |
10086 ms |
74940 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
47448 KB |
Output is correct |
2 |
Correct |
12 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47192 KB |
Output is correct |
5 |
Correct |
12 ms |
47244 KB |
Output is correct |
6 |
Correct |
11 ms |
47196 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
10 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47216 KB |
Output is correct |
11 |
Correct |
11 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
16 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47196 KB |
Output is correct |
15 |
Correct |
12 ms |
47224 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
16 ms |
47572 KB |
Output is correct |
18 |
Correct |
19 ms |
47708 KB |
Output is correct |
19 |
Correct |
22 ms |
47652 KB |
Output is correct |
20 |
Correct |
17 ms |
47452 KB |
Output is correct |
21 |
Correct |
20 ms |
47712 KB |
Output is correct |
22 |
Correct |
21 ms |
47708 KB |
Output is correct |
23 |
Correct |
20 ms |
47800 KB |
Output is correct |
24 |
Execution timed out |
10086 ms |
74940 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
47448 KB |
Output is correct |
2 |
Correct |
12 ms |
47196 KB |
Output is correct |
3 |
Correct |
11 ms |
47196 KB |
Output is correct |
4 |
Correct |
12 ms |
47192 KB |
Output is correct |
5 |
Correct |
12 ms |
47244 KB |
Output is correct |
6 |
Correct |
11 ms |
47196 KB |
Output is correct |
7 |
Correct |
12 ms |
47192 KB |
Output is correct |
8 |
Correct |
10 ms |
47196 KB |
Output is correct |
9 |
Correct |
11 ms |
47196 KB |
Output is correct |
10 |
Correct |
11 ms |
47216 KB |
Output is correct |
11 |
Correct |
11 ms |
47192 KB |
Output is correct |
12 |
Correct |
12 ms |
47196 KB |
Output is correct |
13 |
Correct |
16 ms |
47196 KB |
Output is correct |
14 |
Correct |
11 ms |
47196 KB |
Output is correct |
15 |
Correct |
12 ms |
47224 KB |
Output is correct |
16 |
Correct |
11 ms |
47196 KB |
Output is correct |
17 |
Correct |
16 ms |
47572 KB |
Output is correct |
18 |
Correct |
19 ms |
47708 KB |
Output is correct |
19 |
Correct |
22 ms |
47652 KB |
Output is correct |
20 |
Correct |
17 ms |
47452 KB |
Output is correct |
21 |
Correct |
20 ms |
47712 KB |
Output is correct |
22 |
Correct |
21 ms |
47708 KB |
Output is correct |
23 |
Correct |
20 ms |
47800 KB |
Output is correct |
24 |
Execution timed out |
10086 ms |
74940 KB |
Time limit exceeded |
25 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10038 ms |
84132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
10038 ms |
84132 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |