Submission #722290

# Submission time Handle Problem Language Result Execution time Memory
722290 2023-04-11T17:17:04 Z Dec0Dedd Bodyguards (CEOI10_bodyguards) C++14
100 / 100
135 ms 22324 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pii;

const ll INF = 1e9+10;

ll r, c;

int solve(vector<pii> vr, vector<pii> vc) {
    ll sz=vc.size(), pc[sz+100]={}, pcnt[sz+100]={};

    for (int i=0; i<sz; ++i) pc[i+1]=pc[i]+vc[i].first*vc[i].second;
    for (int i=0; i<sz; ++i) pcnt[i+1]=pcnt[i]+vc[i].second;

    ll sm=0, cnt=0, ls=0;
    for (auto u : vc) ls+=u.first*u.second;

    for (auto u : vr) {
        sm+=u.first*u.second, cnt+=u.second;

        int l=0, r=sz, res=sz-1;
        while (l <= r) {
            int m=(l+r)/2;
            if (vc[m].first >= cnt) l=m+1, res=m;
            else r=m-1;
        }
        if (vc[res].first < cnt) --res;

        

        if (pcnt[res+1] > LLONG_MAX/cnt) continue;
        ll g=1ll*pcnt[res+1]*cnt+(ls-pc[res+1]);
        assert(g >= 0);
        
        if (g < sm) return false;
    }

    return true;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);

    vector<pii> vr, vc;
    cin>>r;

    ll rsm=0, csm=0;
    for (int i=1; i<=r; ++i) {
        ll x, val; cin>>val>>x;
        vr.push_back({val, x});
        rsm+=val*x;   
    } sort(vr.begin(), vr.end(), greater<pii>());

    cin>>c;
    for (int i=1; i<=c; ++i) {
        ll x, val; cin>>val>>x;
        vc.push_back({val, x});
        csm+=val*x;
    } sort(vc.begin(), vc.end(), greater<pii>());

    if (rsm != csm) cout<<0<<"\n";
    else cout<<solve(vr, vc)<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 324 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 324 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 320 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 316 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 316 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 320 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 320 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 324 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 2 ms 328 KB Output is correct
10 Correct 1 ms 352 KB Output is correct
11 Correct 1 ms 352 KB Output is correct
12 Correct 2 ms 352 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 352 KB Output is correct
15 Correct 1 ms 352 KB Output is correct
16 Correct 2 ms 352 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 352 KB Output is correct
2 Correct 1 ms 224 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 224 KB Output is correct
5 Correct 1 ms 224 KB Output is correct
6 Correct 1 ms 224 KB Output is correct
7 Correct 1 ms 224 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 328 KB Output is correct
11 Correct 1 ms 224 KB Output is correct
12 Correct 1 ms 224 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 224 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 852 KB Output is correct
2 Correct 3 ms 596 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 3 ms 724 KB Output is correct
6 Correct 5 ms 852 KB Output is correct
7 Correct 3 ms 852 KB Output is correct
8 Correct 3 ms 712 KB Output is correct
9 Correct 4 ms 840 KB Output is correct
10 Correct 4 ms 844 KB Output is correct
11 Correct 4 ms 788 KB Output is correct
12 Correct 6 ms 784 KB Output is correct
13 Correct 4 ms 832 KB Output is correct
14 Correct 5 ms 840 KB Output is correct
15 Correct 4 ms 976 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 3 ms 892 KB Output is correct
18 Correct 4 ms 792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 21 ms 3088 KB Output is correct
2 Correct 16 ms 3088 KB Output is correct
3 Correct 29 ms 4888 KB Output is correct
4 Correct 34 ms 4688 KB Output is correct
5 Correct 27 ms 4644 KB Output is correct
6 Correct 31 ms 5708 KB Output is correct
7 Correct 23 ms 3868 KB Output is correct
8 Correct 30 ms 5708 KB Output is correct
9 Correct 26 ms 5524 KB Output is correct
10 Correct 34 ms 5404 KB Output is correct
11 Correct 32 ms 5456 KB Output is correct
12 Correct 30 ms 5744 KB Output is correct
13 Correct 28 ms 5472 KB Output is correct
14 Correct 28 ms 5672 KB Output is correct
15 Correct 30 ms 5576 KB Output is correct
16 Correct 33 ms 5628 KB Output is correct
17 Correct 29 ms 5576 KB Output is correct
18 Correct 28 ms 5388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 6596 KB Output is correct
2 Correct 42 ms 7220 KB Output is correct
3 Correct 59 ms 9788 KB Output is correct
4 Correct 12 ms 1740 KB Output is correct
5 Correct 65 ms 10948 KB Output is correct
6 Correct 52 ms 8684 KB Output is correct
7 Correct 57 ms 10140 KB Output is correct
8 Correct 7 ms 1748 KB Output is correct
9 Correct 57 ms 10984 KB Output is correct
10 Correct 53 ms 10312 KB Output is correct
11 Correct 55 ms 10476 KB Output is correct
12 Correct 56 ms 10388 KB Output is correct
13 Correct 58 ms 10952 KB Output is correct
14 Correct 63 ms 10812 KB Output is correct
15 Correct 63 ms 10828 KB Output is correct
16 Correct 59 ms 10796 KB Output is correct
17 Correct 59 ms 10800 KB Output is correct
18 Correct 65 ms 10808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 84 ms 11320 KB Output is correct
2 Correct 79 ms 11228 KB Output is correct
3 Correct 72 ms 10372 KB Output is correct
4 Correct 33 ms 4428 KB Output is correct
5 Correct 106 ms 14844 KB Output is correct
6 Correct 90 ms 22324 KB Output is correct
7 Correct 67 ms 12356 KB Output is correct
8 Correct 89 ms 16312 KB Output is correct
9 Correct 110 ms 20296 KB Output is correct
10 Correct 108 ms 20244 KB Output is correct
11 Correct 101 ms 20284 KB Output is correct
12 Correct 115 ms 20188 KB Output is correct
13 Correct 114 ms 20208 KB Output is correct
14 Correct 11 ms 2252 KB Output is correct
15 Correct 135 ms 21708 KB Output is correct
16 Correct 125 ms 21624 KB Output is correct
17 Correct 133 ms 21732 KB Output is correct
18 Correct 117 ms 20212 KB Output is correct