Submission #362437

# Submission time Handle Problem Language Result Execution time Memory
362437 2021-02-03T08:39:50 Z Yeboi Art Exhibition (JOI18_art) C++14
100 / 100
636 ms 44728 KB
#include <bits/stdc++.h>
#define ll long long
#define mod 998244353
#define rep(i,s) for(ll i=0; i<s ; i++)
#define f(i,a,b) for(long long i(a); i<b ; i++)
#define inf -pow(10,9)
#define MAXN 100000 
const ll INF = 1000000000;
const ll N = 50005;
const ll modi = 1000000007;
const ll modi2= 1000000006;
using namespace std;

int main(){
        ll n;
        cin >> n;
        ll a[n+1];
        ll b[n+1];
        vector<pair<ll,ll>> v;
        rep(i,n){
            cin >> a[i] >> b[i];
            v.push_back(make_pair(a[i],b[i]));
        }
        sort(v.begin(),v.end());
        rep(i,n){
            a[i]=v[i].first;
            b[i]=v[i].second;
        }
        ll pre[n+1]={0};
        pre[0]=b[0];
        f(i,1,n){
            pre[i]=pre[i-1]+b[i];
        }
        ll p1[n+1];
        ll p2[n+1];
        rep(i,n){
            p1[i]=pre[i]-a[i];
            if(i==0){
                continue;
            }
            p2[i]=pre[i-1]-a[i];
        }
        ll curr[n+1];
        curr[0]=1e18;
        f(i,1,n){   
            curr[i]=min(curr[i-1],p2[i]);
        }
        ll ans=b[0]-a[0];
        f(i,1,n){
            ans=max(ans,p1[i]-curr[i]);
            ans=max(ans,p1[i]+a[0]);
        }   
        cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 7 ms 876 KB Output is correct
28 Correct 8 ms 876 KB Output is correct
29 Correct 6 ms 876 KB Output is correct
30 Correct 6 ms 876 KB Output is correct
31 Correct 7 ms 1024 KB Output is correct
32 Correct 6 ms 876 KB Output is correct
33 Correct 8 ms 876 KB Output is correct
34 Correct 6 ms 876 KB Output is correct
35 Correct 6 ms 876 KB Output is correct
36 Correct 7 ms 876 KB Output is correct
37 Correct 6 ms 876 KB Output is correct
38 Correct 6 ms 876 KB Output is correct
39 Correct 6 ms 1004 KB Output is correct
40 Correct 6 ms 896 KB Output is correct
41 Correct 6 ms 876 KB Output is correct
42 Correct 8 ms 876 KB Output is correct
43 Correct 6 ms 876 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 6 ms 876 KB Output is correct
46 Correct 6 ms 876 KB Output is correct
47 Correct 7 ms 876 KB Output is correct
48 Correct 7 ms 876 KB Output is correct
49 Correct 6 ms 876 KB Output is correct
50 Correct 6 ms 876 KB Output is correct
51 Correct 6 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 500 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 396 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 7 ms 876 KB Output is correct
28 Correct 8 ms 876 KB Output is correct
29 Correct 6 ms 876 KB Output is correct
30 Correct 6 ms 876 KB Output is correct
31 Correct 7 ms 1024 KB Output is correct
32 Correct 6 ms 876 KB Output is correct
33 Correct 8 ms 876 KB Output is correct
34 Correct 6 ms 876 KB Output is correct
35 Correct 6 ms 876 KB Output is correct
36 Correct 7 ms 876 KB Output is correct
37 Correct 6 ms 876 KB Output is correct
38 Correct 6 ms 876 KB Output is correct
39 Correct 6 ms 1004 KB Output is correct
40 Correct 6 ms 896 KB Output is correct
41 Correct 6 ms 876 KB Output is correct
42 Correct 8 ms 876 KB Output is correct
43 Correct 6 ms 876 KB Output is correct
44 Correct 6 ms 876 KB Output is correct
45 Correct 6 ms 876 KB Output is correct
46 Correct 6 ms 876 KB Output is correct
47 Correct 7 ms 876 KB Output is correct
48 Correct 7 ms 876 KB Output is correct
49 Correct 6 ms 876 KB Output is correct
50 Correct 6 ms 876 KB Output is correct
51 Correct 6 ms 876 KB Output is correct
52 Correct 596 ms 44624 KB Output is correct
53 Correct 636 ms 44624 KB Output is correct
54 Correct 589 ms 44360 KB Output is correct
55 Correct 580 ms 44492 KB Output is correct
56 Correct 608 ms 44568 KB Output is correct
57 Correct 582 ms 44676 KB Output is correct
58 Correct 604 ms 44488 KB Output is correct
59 Correct 585 ms 44572 KB Output is correct
60 Correct 583 ms 44436 KB Output is correct
61 Correct 576 ms 44360 KB Output is correct
62 Correct 589 ms 44360 KB Output is correct
63 Correct 583 ms 44360 KB Output is correct
64 Correct 583 ms 44640 KB Output is correct
65 Correct 604 ms 44464 KB Output is correct
66 Correct 591 ms 44728 KB Output is correct
67 Correct 619 ms 44648 KB Output is correct
68 Correct 588 ms 44488 KB Output is correct