Submission #863104

# Submission time Handle Problem Language Result Execution time Memory
863104 2023-10-19T15:25:46 Z efedmrlr Art Exhibition (JOI18_art) C++17
100 / 100
175 ms 30792 KB
#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define MP make_pair
#define pb push_back
#define REP(i,n) for(int (i) = 0; (i) < (n); (i)++)

void fastio() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}


const double EPS = 0.00001;
const int INF = 1e17+500;
const int N = 1e5+5;
const int M = 3e5+5;
const int ALPH = 26;
const int LGN = 25;
const int MOD = 1e9+7;
int n,m,q;
vector<array<int,2> > arr; // sz, price
vector<int> pref;



inline void solve() {
    cin>>n;
    arr.resize(n);
    for(int i = 0; i<n; i++) {
        cin >> arr[i][0] >> arr[i][1];
    }
    arr.pb({0,0});
    sort(arr.begin(), arr.end());
    pref.resize(n+1);
    pref[0] = 0;
    for(int i = 1; i<=n; i++) {
        pref[i] = pref[i-1] + arr[i][1];
    }
    int mx = -INF;
    int ans = -INF;
    for (int i = n; i >= 1; i--)
    {
        mx = max(mx, pref[i] - arr[i][0]);
        ans = max(ans, mx + arr[i][0] - pref[i-1]);
    }
    cout<<ans<<"\n";
    

}
 
signed main() {
    fastio();
    int test = 1;
    //cin>>test;
    while(test--) {
        solve();
    }
    
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 448 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 448 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 720 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 728 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 660 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 676 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 2 ms 672 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 900 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 668 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 460 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 0 ms 344 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 448 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 600 KB Output is correct
27 Correct 2 ms 604 KB Output is correct
28 Correct 2 ms 720 KB Output is correct
29 Correct 2 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 2 ms 604 KB Output is correct
32 Correct 2 ms 600 KB Output is correct
33 Correct 2 ms 728 KB Output is correct
34 Correct 2 ms 600 KB Output is correct
35 Correct 2 ms 660 KB Output is correct
36 Correct 2 ms 604 KB Output is correct
37 Correct 2 ms 604 KB Output is correct
38 Correct 2 ms 604 KB Output is correct
39 Correct 2 ms 676 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 2 ms 604 KB Output is correct
42 Correct 2 ms 724 KB Output is correct
43 Correct 2 ms 672 KB Output is correct
44 Correct 2 ms 604 KB Output is correct
45 Correct 2 ms 604 KB Output is correct
46 Correct 2 ms 900 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 2 ms 604 KB Output is correct
49 Correct 2 ms 668 KB Output is correct
50 Correct 2 ms 600 KB Output is correct
51 Correct 2 ms 604 KB Output is correct
52 Correct 157 ms 29632 KB Output is correct
53 Correct 175 ms 30532 KB Output is correct
54 Correct 138 ms 30536 KB Output is correct
55 Correct 137 ms 29376 KB Output is correct
56 Correct 144 ms 29896 KB Output is correct
57 Correct 137 ms 30656 KB Output is correct
58 Correct 139 ms 29008 KB Output is correct
59 Correct 138 ms 30400 KB Output is correct
60 Correct 137 ms 29120 KB Output is correct
61 Correct 145 ms 29120 KB Output is correct
62 Correct 136 ms 29636 KB Output is correct
63 Correct 136 ms 30032 KB Output is correct
64 Correct 137 ms 29520 KB Output is correct
65 Correct 139 ms 30016 KB Output is correct
66 Correct 147 ms 30144 KB Output is correct
67 Correct 150 ms 30792 KB Output is correct
68 Correct 138 ms 29268 KB Output is correct