Submission #70857

# Submission time Handle Problem Language Result Execution time Memory
70857 2018-08-23T14:18:26 Z someone_aa Art Exhibition (JOI18_art) C++17
100 / 100
870 ms 227116 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 500100;
map<ll, ll> sum;
vector<pair<ll, ll> > values;
vector<ll> pref;
ll n, x, y;

ll get_val(int l, int r) {
    ll sum =1LL* pref[r] - pref[l-1];
    ll diff = values[r].first - values[l].first;
    return sum - diff;
}

vector<pair<ll,ll> > temp;

int main() {
    //ios_base::sync_with_stdio(false);
    //cin.tie(0);
    cin>>n;
    temp.pb(mp(0,0));
    for(int i=0;i<n;i++) {
        cin>>x>>y;
        temp.pb(mp(x,y));
    }
    sort(temp.begin(), temp.end());
    values.pb(mp(0,0));
    for(int i=1;i<=n;i++) {
        if(temp[i].first != temp[i-1].first) {
            values.pb(mp(temp[i].first, temp[i].second));
        }
        else {
            values[values.size()-1].second += temp[i].second;
        }
    }

    pref.pb(0LL);
    for(int i=1;i<values.size();i++) {
        pref.pb(pref.back() + values[i].second);
    }

    ll l = 1LL;
    ll result = get_val(1,1);
    ll max_pref = values[1].first;
    for(ll i=2;i<values.size();i++) {
        max_pref = max(max_pref, values[i].first - pref[i-1]);
        ll curr_val = pref[i] - values[i].first + max_pref;
        result = max(result, curr_val);
    }
    cout<<result;

    return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:41:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<values.size();i++) {
                 ~^~~~~~~~~~~~~~
art.cpp:48:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i=2;i<values.size();i++) {
                ~^~~~~~~~~~~~~~
art.cpp:45:8: warning: unused variable 'l' [-Wunused-variable]
     ll l = 1LL;
        ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 4 ms 716 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 4 ms 716 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 13 ms 876 KB Output is correct
28 Correct 11 ms 876 KB Output is correct
29 Correct 12 ms 876 KB Output is correct
30 Correct 10 ms 876 KB Output is correct
31 Correct 12 ms 876 KB Output is correct
32 Correct 10 ms 876 KB Output is correct
33 Correct 12 ms 876 KB Output is correct
34 Correct 11 ms 876 KB Output is correct
35 Correct 11 ms 876 KB Output is correct
36 Correct 10 ms 896 KB Output is correct
37 Correct 9 ms 896 KB Output is correct
38 Correct 11 ms 896 KB Output is correct
39 Correct 11 ms 896 KB Output is correct
40 Correct 9 ms 896 KB Output is correct
41 Correct 11 ms 896 KB Output is correct
42 Correct 8 ms 896 KB Output is correct
43 Correct 9 ms 896 KB Output is correct
44 Correct 8 ms 896 KB Output is correct
45 Correct 11 ms 896 KB Output is correct
46 Correct 9 ms 896 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
48 Correct 9 ms 896 KB Output is correct
49 Correct 10 ms 896 KB Output is correct
50 Correct 11 ms 896 KB Output is correct
51 Correct 9 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 500 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 3 ms 600 KB Output is correct
6 Correct 3 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 3 ms 600 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
13 Correct 3 ms 600 KB Output is correct
14 Correct 3 ms 600 KB Output is correct
15 Correct 3 ms 600 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 3 ms 600 KB Output is correct
18 Correct 3 ms 600 KB Output is correct
19 Correct 2 ms 600 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 4 ms 716 KB Output is correct
24 Correct 4 ms 716 KB Output is correct
25 Correct 3 ms 716 KB Output is correct
26 Correct 3 ms 716 KB Output is correct
27 Correct 13 ms 876 KB Output is correct
28 Correct 11 ms 876 KB Output is correct
29 Correct 12 ms 876 KB Output is correct
30 Correct 10 ms 876 KB Output is correct
31 Correct 12 ms 876 KB Output is correct
32 Correct 10 ms 876 KB Output is correct
33 Correct 12 ms 876 KB Output is correct
34 Correct 11 ms 876 KB Output is correct
35 Correct 11 ms 876 KB Output is correct
36 Correct 10 ms 896 KB Output is correct
37 Correct 9 ms 896 KB Output is correct
38 Correct 11 ms 896 KB Output is correct
39 Correct 11 ms 896 KB Output is correct
40 Correct 9 ms 896 KB Output is correct
41 Correct 11 ms 896 KB Output is correct
42 Correct 8 ms 896 KB Output is correct
43 Correct 9 ms 896 KB Output is correct
44 Correct 8 ms 896 KB Output is correct
45 Correct 11 ms 896 KB Output is correct
46 Correct 9 ms 896 KB Output is correct
47 Correct 9 ms 896 KB Output is correct
48 Correct 9 ms 896 KB Output is correct
49 Correct 10 ms 896 KB Output is correct
50 Correct 11 ms 896 KB Output is correct
51 Correct 9 ms 896 KB Output is correct
52 Correct 764 ms 24480 KB Output is correct
53 Correct 808 ms 37176 KB Output is correct
54 Correct 845 ms 49772 KB Output is correct
55 Correct 853 ms 62392 KB Output is correct
56 Correct 835 ms 75160 KB Output is correct
57 Correct 856 ms 87820 KB Output is correct
58 Correct 870 ms 100612 KB Output is correct
59 Correct 801 ms 113268 KB Output is correct
60 Correct 781 ms 125836 KB Output is correct
61 Correct 697 ms 138444 KB Output is correct
62 Correct 863 ms 151092 KB Output is correct
63 Correct 790 ms 163760 KB Output is correct
64 Correct 763 ms 176300 KB Output is correct
65 Correct 708 ms 189116 KB Output is correct
66 Correct 720 ms 201636 KB Output is correct
67 Correct 765 ms 214308 KB Output is correct
68 Correct 802 ms 227116 KB Output is correct