답안 #995407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
995407 2024-06-09T03:23:36 Z browntoad Two Dishes (JOI19_dishes) C++14
100 / 100
1472 ms 265700 KB
#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:vv){
        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 val:mp) ans += val.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 :)
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 75472 KB Output is correct
2 Correct 190 ms 71092 KB Output is correct
3 Correct 125 ms 64504 KB Output is correct
4 Correct 194 ms 66740 KB Output is correct
5 Correct 14 ms 47196 KB Output is correct
6 Correct 191 ms 83392 KB Output is correct
7 Correct 59 ms 55768 KB Output is correct
8 Correct 78 ms 69832 KB Output is correct
9 Correct 135 ms 79036 KB Output is correct
10 Correct 186 ms 78028 KB Output is correct
11 Correct 104 ms 72160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47196 KB Output is correct
2 Correct 11 ms 47196 KB Output is correct
3 Correct 11 ms 47196 KB Output is correct
4 Correct 12 ms 47212 KB Output is correct
5 Correct 11 ms 47340 KB Output is correct
6 Correct 13 ms 47196 KB Output is correct
7 Correct 11 ms 47404 KB Output is correct
8 Correct 12 ms 47428 KB Output is correct
9 Correct 12 ms 47220 KB Output is correct
10 Correct 12 ms 47196 KB Output is correct
11 Correct 12 ms 47192 KB Output is correct
12 Correct 12 ms 47260 KB Output is correct
13 Correct 12 ms 47256 KB Output is correct
14 Correct 12 ms 47196 KB Output is correct
15 Correct 12 ms 47196 KB Output is correct
16 Correct 12 ms 47312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47196 KB Output is correct
2 Correct 11 ms 47196 KB Output is correct
3 Correct 11 ms 47196 KB Output is correct
4 Correct 12 ms 47212 KB Output is correct
5 Correct 11 ms 47340 KB Output is correct
6 Correct 13 ms 47196 KB Output is correct
7 Correct 11 ms 47404 KB Output is correct
8 Correct 12 ms 47428 KB Output is correct
9 Correct 12 ms 47220 KB Output is correct
10 Correct 12 ms 47196 KB Output is correct
11 Correct 12 ms 47192 KB Output is correct
12 Correct 12 ms 47260 KB Output is correct
13 Correct 12 ms 47256 KB Output is correct
14 Correct 12 ms 47196 KB Output is correct
15 Correct 12 ms 47196 KB Output is correct
16 Correct 12 ms 47312 KB Output is correct
17 Correct 12 ms 47452 KB Output is correct
18 Correct 13 ms 47640 KB Output is correct
19 Correct 14 ms 47708 KB Output is correct
20 Correct 13 ms 47452 KB Output is correct
21 Correct 13 ms 47508 KB Output is correct
22 Correct 13 ms 47708 KB Output is correct
23 Correct 13 ms 47660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47196 KB Output is correct
2 Correct 11 ms 47196 KB Output is correct
3 Correct 11 ms 47196 KB Output is correct
4 Correct 12 ms 47212 KB Output is correct
5 Correct 11 ms 47340 KB Output is correct
6 Correct 13 ms 47196 KB Output is correct
7 Correct 11 ms 47404 KB Output is correct
8 Correct 12 ms 47428 KB Output is correct
9 Correct 12 ms 47220 KB Output is correct
10 Correct 12 ms 47196 KB Output is correct
11 Correct 12 ms 47192 KB Output is correct
12 Correct 12 ms 47260 KB Output is correct
13 Correct 12 ms 47256 KB Output is correct
14 Correct 12 ms 47196 KB Output is correct
15 Correct 12 ms 47196 KB Output is correct
16 Correct 12 ms 47312 KB Output is correct
17 Correct 12 ms 47452 KB Output is correct
18 Correct 13 ms 47640 KB Output is correct
19 Correct 14 ms 47708 KB Output is correct
20 Correct 13 ms 47452 KB Output is correct
21 Correct 13 ms 47508 KB Output is correct
22 Correct 13 ms 47708 KB Output is correct
23 Correct 13 ms 47660 KB Output is correct
24 Correct 112 ms 64448 KB Output is correct
25 Correct 223 ms 87560 KB Output is correct
26 Correct 125 ms 74980 KB Output is correct
27 Correct 200 ms 87860 KB Output is correct
28 Correct 155 ms 75728 KB Output is correct
29 Correct 119 ms 75708 KB Output is correct
30 Correct 250 ms 88784 KB Output is correct
31 Correct 84 ms 65136 KB Output is correct
32 Correct 86 ms 68024 KB Output is correct
33 Correct 168 ms 74548 KB Output is correct
34 Correct 225 ms 87964 KB Output is correct
35 Correct 230 ms 82344 KB Output is correct
36 Correct 229 ms 82340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47196 KB Output is correct
2 Correct 11 ms 47196 KB Output is correct
3 Correct 11 ms 47196 KB Output is correct
4 Correct 12 ms 47212 KB Output is correct
5 Correct 11 ms 47340 KB Output is correct
6 Correct 13 ms 47196 KB Output is correct
7 Correct 11 ms 47404 KB Output is correct
8 Correct 12 ms 47428 KB Output is correct
9 Correct 12 ms 47220 KB Output is correct
10 Correct 12 ms 47196 KB Output is correct
11 Correct 12 ms 47192 KB Output is correct
12 Correct 12 ms 47260 KB Output is correct
13 Correct 12 ms 47256 KB Output is correct
14 Correct 12 ms 47196 KB Output is correct
15 Correct 12 ms 47196 KB Output is correct
16 Correct 12 ms 47312 KB Output is correct
17 Correct 12 ms 47452 KB Output is correct
18 Correct 13 ms 47640 KB Output is correct
19 Correct 14 ms 47708 KB Output is correct
20 Correct 13 ms 47452 KB Output is correct
21 Correct 13 ms 47508 KB Output is correct
22 Correct 13 ms 47708 KB Output is correct
23 Correct 13 ms 47660 KB Output is correct
24 Correct 112 ms 64448 KB Output is correct
25 Correct 223 ms 87560 KB Output is correct
26 Correct 125 ms 74980 KB Output is correct
27 Correct 200 ms 87860 KB Output is correct
28 Correct 155 ms 75728 KB Output is correct
29 Correct 119 ms 75708 KB Output is correct
30 Correct 250 ms 88784 KB Output is correct
31 Correct 84 ms 65136 KB Output is correct
32 Correct 86 ms 68024 KB Output is correct
33 Correct 168 ms 74548 KB Output is correct
34 Correct 225 ms 87964 KB Output is correct
35 Correct 230 ms 82344 KB Output is correct
36 Correct 229 ms 82340 KB Output is correct
37 Correct 132 ms 78016 KB Output is correct
38 Correct 248 ms 90636 KB Output is correct
39 Correct 253 ms 88004 KB Output is correct
40 Correct 199 ms 81740 KB Output is correct
41 Correct 10 ms 47192 KB Output is correct
42 Correct 270 ms 91856 KB Output is correct
43 Correct 177 ms 77476 KB Output is correct
44 Correct 242 ms 90876 KB Output is correct
45 Correct 261 ms 85668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 47196 KB Output is correct
2 Correct 11 ms 47196 KB Output is correct
3 Correct 11 ms 47196 KB Output is correct
4 Correct 12 ms 47212 KB Output is correct
5 Correct 11 ms 47340 KB Output is correct
6 Correct 13 ms 47196 KB Output is correct
7 Correct 11 ms 47404 KB Output is correct
8 Correct 12 ms 47428 KB Output is correct
9 Correct 12 ms 47220 KB Output is correct
10 Correct 12 ms 47196 KB Output is correct
11 Correct 12 ms 47192 KB Output is correct
12 Correct 12 ms 47260 KB Output is correct
13 Correct 12 ms 47256 KB Output is correct
14 Correct 12 ms 47196 KB Output is correct
15 Correct 12 ms 47196 KB Output is correct
16 Correct 12 ms 47312 KB Output is correct
17 Correct 12 ms 47452 KB Output is correct
18 Correct 13 ms 47640 KB Output is correct
19 Correct 14 ms 47708 KB Output is correct
20 Correct 13 ms 47452 KB Output is correct
21 Correct 13 ms 47508 KB Output is correct
22 Correct 13 ms 47708 KB Output is correct
23 Correct 13 ms 47660 KB Output is correct
24 Correct 112 ms 64448 KB Output is correct
25 Correct 223 ms 87560 KB Output is correct
26 Correct 125 ms 74980 KB Output is correct
27 Correct 200 ms 87860 KB Output is correct
28 Correct 155 ms 75728 KB Output is correct
29 Correct 119 ms 75708 KB Output is correct
30 Correct 250 ms 88784 KB Output is correct
31 Correct 84 ms 65136 KB Output is correct
32 Correct 86 ms 68024 KB Output is correct
33 Correct 168 ms 74548 KB Output is correct
34 Correct 225 ms 87964 KB Output is correct
35 Correct 230 ms 82344 KB Output is correct
36 Correct 229 ms 82340 KB Output is correct
37 Correct 132 ms 78016 KB Output is correct
38 Correct 248 ms 90636 KB Output is correct
39 Correct 253 ms 88004 KB Output is correct
40 Correct 199 ms 81740 KB Output is correct
41 Correct 10 ms 47192 KB Output is correct
42 Correct 270 ms 91856 KB Output is correct
43 Correct 177 ms 77476 KB Output is correct
44 Correct 242 ms 90876 KB Output is correct
45 Correct 261 ms 85668 KB Output is correct
46 Correct 698 ms 193320 KB Output is correct
47 Correct 1386 ms 265700 KB Output is correct
48 Correct 1367 ms 252232 KB Output is correct
49 Correct 1000 ms 214400 KB Output is correct
50 Correct 1457 ms 253152 KB Output is correct
51 Correct 1000 ms 188464 KB Output is correct
52 Correct 1340 ms 242780 KB Output is correct
53 Correct 1380 ms 220520 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 75472 KB Output is correct
2 Correct 190 ms 71092 KB Output is correct
3 Correct 125 ms 64504 KB Output is correct
4 Correct 194 ms 66740 KB Output is correct
5 Correct 14 ms 47196 KB Output is correct
6 Correct 191 ms 83392 KB Output is correct
7 Correct 59 ms 55768 KB Output is correct
8 Correct 78 ms 69832 KB Output is correct
9 Correct 135 ms 79036 KB Output is correct
10 Correct 186 ms 78028 KB Output is correct
11 Correct 104 ms 72160 KB Output is correct
12 Correct 11 ms 47196 KB Output is correct
13 Correct 11 ms 47196 KB Output is correct
14 Correct 11 ms 47196 KB Output is correct
15 Correct 12 ms 47212 KB Output is correct
16 Correct 11 ms 47340 KB Output is correct
17 Correct 13 ms 47196 KB Output is correct
18 Correct 11 ms 47404 KB Output is correct
19 Correct 12 ms 47428 KB Output is correct
20 Correct 12 ms 47220 KB Output is correct
21 Correct 12 ms 47196 KB Output is correct
22 Correct 12 ms 47192 KB Output is correct
23 Correct 12 ms 47260 KB Output is correct
24 Correct 12 ms 47256 KB Output is correct
25 Correct 12 ms 47196 KB Output is correct
26 Correct 12 ms 47196 KB Output is correct
27 Correct 12 ms 47312 KB Output is correct
28 Correct 12 ms 47452 KB Output is correct
29 Correct 13 ms 47640 KB Output is correct
30 Correct 14 ms 47708 KB Output is correct
31 Correct 13 ms 47452 KB Output is correct
32 Correct 13 ms 47508 KB Output is correct
33 Correct 13 ms 47708 KB Output is correct
34 Correct 13 ms 47660 KB Output is correct
35 Correct 112 ms 64448 KB Output is correct
36 Correct 223 ms 87560 KB Output is correct
37 Correct 125 ms 74980 KB Output is correct
38 Correct 200 ms 87860 KB Output is correct
39 Correct 155 ms 75728 KB Output is correct
40 Correct 119 ms 75708 KB Output is correct
41 Correct 250 ms 88784 KB Output is correct
42 Correct 84 ms 65136 KB Output is correct
43 Correct 86 ms 68024 KB Output is correct
44 Correct 168 ms 74548 KB Output is correct
45 Correct 225 ms 87964 KB Output is correct
46 Correct 230 ms 82344 KB Output is correct
47 Correct 229 ms 82340 KB Output is correct
48 Correct 132 ms 78016 KB Output is correct
49 Correct 248 ms 90636 KB Output is correct
50 Correct 253 ms 88004 KB Output is correct
51 Correct 199 ms 81740 KB Output is correct
52 Correct 10 ms 47192 KB Output is correct
53 Correct 270 ms 91856 KB Output is correct
54 Correct 177 ms 77476 KB Output is correct
55 Correct 242 ms 90876 KB Output is correct
56 Correct 261 ms 85668 KB Output is correct
57 Correct 199 ms 86856 KB Output is correct
58 Correct 175 ms 90020 KB Output is correct
59 Correct 207 ms 82632 KB Output is correct
60 Correct 257 ms 88904 KB Output is correct
61 Correct 215 ms 89000 KB Output is correct
62 Correct 10 ms 47196 KB Output is correct
63 Correct 270 ms 91840 KB Output is correct
64 Correct 181 ms 77724 KB Output is correct
65 Correct 237 ms 92272 KB Output is correct
66 Correct 258 ms 85468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 255 ms 75472 KB Output is correct
2 Correct 190 ms 71092 KB Output is correct
3 Correct 125 ms 64504 KB Output is correct
4 Correct 194 ms 66740 KB Output is correct
5 Correct 14 ms 47196 KB Output is correct
6 Correct 191 ms 83392 KB Output is correct
7 Correct 59 ms 55768 KB Output is correct
8 Correct 78 ms 69832 KB Output is correct
9 Correct 135 ms 79036 KB Output is correct
10 Correct 186 ms 78028 KB Output is correct
11 Correct 104 ms 72160 KB Output is correct
12 Correct 11 ms 47196 KB Output is correct
13 Correct 11 ms 47196 KB Output is correct
14 Correct 11 ms 47196 KB Output is correct
15 Correct 12 ms 47212 KB Output is correct
16 Correct 11 ms 47340 KB Output is correct
17 Correct 13 ms 47196 KB Output is correct
18 Correct 11 ms 47404 KB Output is correct
19 Correct 12 ms 47428 KB Output is correct
20 Correct 12 ms 47220 KB Output is correct
21 Correct 12 ms 47196 KB Output is correct
22 Correct 12 ms 47192 KB Output is correct
23 Correct 12 ms 47260 KB Output is correct
24 Correct 12 ms 47256 KB Output is correct
25 Correct 12 ms 47196 KB Output is correct
26 Correct 12 ms 47196 KB Output is correct
27 Correct 12 ms 47312 KB Output is correct
28 Correct 12 ms 47452 KB Output is correct
29 Correct 13 ms 47640 KB Output is correct
30 Correct 14 ms 47708 KB Output is correct
31 Correct 13 ms 47452 KB Output is correct
32 Correct 13 ms 47508 KB Output is correct
33 Correct 13 ms 47708 KB Output is correct
34 Correct 13 ms 47660 KB Output is correct
35 Correct 112 ms 64448 KB Output is correct
36 Correct 223 ms 87560 KB Output is correct
37 Correct 125 ms 74980 KB Output is correct
38 Correct 200 ms 87860 KB Output is correct
39 Correct 155 ms 75728 KB Output is correct
40 Correct 119 ms 75708 KB Output is correct
41 Correct 250 ms 88784 KB Output is correct
42 Correct 84 ms 65136 KB Output is correct
43 Correct 86 ms 68024 KB Output is correct
44 Correct 168 ms 74548 KB Output is correct
45 Correct 225 ms 87964 KB Output is correct
46 Correct 230 ms 82344 KB Output is correct
47 Correct 229 ms 82340 KB Output is correct
48 Correct 132 ms 78016 KB Output is correct
49 Correct 248 ms 90636 KB Output is correct
50 Correct 253 ms 88004 KB Output is correct
51 Correct 199 ms 81740 KB Output is correct
52 Correct 10 ms 47192 KB Output is correct
53 Correct 270 ms 91856 KB Output is correct
54 Correct 177 ms 77476 KB Output is correct
55 Correct 242 ms 90876 KB Output is correct
56 Correct 261 ms 85668 KB Output is correct
57 Correct 698 ms 193320 KB Output is correct
58 Correct 1386 ms 265700 KB Output is correct
59 Correct 1367 ms 252232 KB Output is correct
60 Correct 1000 ms 214400 KB Output is correct
61 Correct 1457 ms 253152 KB Output is correct
62 Correct 1000 ms 188464 KB Output is correct
63 Correct 1340 ms 242780 KB Output is correct
64 Correct 1380 ms 220520 KB Output is correct
65 Correct 199 ms 86856 KB Output is correct
66 Correct 175 ms 90020 KB Output is correct
67 Correct 207 ms 82632 KB Output is correct
68 Correct 257 ms 88904 KB Output is correct
69 Correct 215 ms 89000 KB Output is correct
70 Correct 10 ms 47196 KB Output is correct
71 Correct 270 ms 91840 KB Output is correct
72 Correct 181 ms 77724 KB Output is correct
73 Correct 237 ms 92272 KB Output is correct
74 Correct 258 ms 85468 KB Output is correct
75 Correct 940 ms 244332 KB Output is correct
76 Correct 828 ms 243800 KB Output is correct
77 Correct 1027 ms 216844 KB Output is correct
78 Correct 1385 ms 254916 KB Output is correct
79 Correct 1472 ms 253784 KB Output is correct
80 Correct 981 ms 189572 KB Output is correct
81 Correct 1228 ms 239188 KB Output is correct
82 Correct 1307 ms 221156 KB Output is correct
83 Correct 1340 ms 239332 KB Output is correct