답안 #488958

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
488958 2021-11-20T20:48:44 Z SlavicG Art Exhibition (JOI18_art) C++17
100 / 100
168 ms 17864 KB
#include "bits/stdc++.h"
using namespace std;
 
#define ll long long
 
#define       forn(i,n)              for(int i=0;i<n;i++)
#define          all(v)              v.begin(), v.end()
#define         rall(v)              v.rbegin(),v.rend()
 
#define            pb                push_back
#define          sz(a)               (int)a.size()

#define int long long
const int N = 5e5 + 10;

ll suf_max[N];

void solve()
{ 
    for(int i = 0;i < N; ++i){
        suf_max[i] = LLONG_MIN;
    }
    int n;
    cin >> n;
    vector<pair<int,int>> a(n);
    vector<int> pref(n);
    for(int i = 0;i < n; ++i){
        cin >> a[i].first >> a[i].second;
    }

    sort(all(a));
    for(int i = 0;i < n; ++i){
        pref[i] = a[i].second;
        if(i)pref[i] += pref[i - 1];
    }
    for(int i = n - 1;i >= 0; --i){
        suf_max[i] = max(suf_max[i + 1], pref[i] - a[i].first);
    }
    ll ans = 0;
    for(int i = 0;i < n; ++i){
        ans = max(ans, a[i].second);
        if(i + 1 < n){
            ans = max(ans, suf_max[i + 1] - pref[i] + a[i].second + a[i].first);
        }
    }

    cout << ans << "\n";
}   
 
int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--)
    {
        solve();
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4232 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4228 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4160 KB Output is correct
8 Correct 2 ms 4172 KB Output is correct
9 Correct 2 ms 4172 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4232 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4228 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4160 KB Output is correct
8 Correct 2 ms 4172 KB Output is correct
9 Correct 2 ms 4172 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 2 ms 4172 KB Output is correct
13 Correct 2 ms 4172 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4232 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4228 KB Output is correct
20 Correct 2 ms 4236 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4232 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4232 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4228 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4160 KB Output is correct
8 Correct 2 ms 4172 KB Output is correct
9 Correct 2 ms 4172 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 2 ms 4172 KB Output is correct
13 Correct 2 ms 4172 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4232 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4228 KB Output is correct
20 Correct 2 ms 4236 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4232 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 3 ms 4428 KB Output is correct
28 Correct 4 ms 4428 KB Output is correct
29 Correct 4 ms 4428 KB Output is correct
30 Correct 4 ms 4456 KB Output is correct
31 Correct 3 ms 4428 KB Output is correct
32 Correct 3 ms 4428 KB Output is correct
33 Correct 3 ms 4428 KB Output is correct
34 Correct 3 ms 4428 KB Output is correct
35 Correct 3 ms 4368 KB Output is correct
36 Correct 4 ms 4428 KB Output is correct
37 Correct 5 ms 4428 KB Output is correct
38 Correct 4 ms 4428 KB Output is correct
39 Correct 4 ms 4372 KB Output is correct
40 Correct 4 ms 4468 KB Output is correct
41 Correct 3 ms 4428 KB Output is correct
42 Correct 3 ms 4428 KB Output is correct
43 Correct 3 ms 4428 KB Output is correct
44 Correct 3 ms 4428 KB Output is correct
45 Correct 3 ms 4428 KB Output is correct
46 Correct 4 ms 4428 KB Output is correct
47 Correct 3 ms 4364 KB Output is correct
48 Correct 4 ms 4372 KB Output is correct
49 Correct 3 ms 4428 KB Output is correct
50 Correct 3 ms 4428 KB Output is correct
51 Correct 3 ms 4428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4172 KB Output is correct
2 Correct 2 ms 4232 KB Output is correct
3 Correct 2 ms 4172 KB Output is correct
4 Correct 2 ms 4228 KB Output is correct
5 Correct 2 ms 4172 KB Output is correct
6 Correct 2 ms 4172 KB Output is correct
7 Correct 2 ms 4160 KB Output is correct
8 Correct 2 ms 4172 KB Output is correct
9 Correct 2 ms 4172 KB Output is correct
10 Correct 2 ms 4172 KB Output is correct
11 Correct 2 ms 4172 KB Output is correct
12 Correct 2 ms 4172 KB Output is correct
13 Correct 2 ms 4172 KB Output is correct
14 Correct 2 ms 4172 KB Output is correct
15 Correct 2 ms 4232 KB Output is correct
16 Correct 2 ms 4172 KB Output is correct
17 Correct 2 ms 4172 KB Output is correct
18 Correct 2 ms 4172 KB Output is correct
19 Correct 2 ms 4228 KB Output is correct
20 Correct 2 ms 4236 KB Output is correct
21 Correct 2 ms 4172 KB Output is correct
22 Correct 2 ms 4172 KB Output is correct
23 Correct 2 ms 4172 KB Output is correct
24 Correct 2 ms 4172 KB Output is correct
25 Correct 2 ms 4232 KB Output is correct
26 Correct 2 ms 4172 KB Output is correct
27 Correct 3 ms 4428 KB Output is correct
28 Correct 4 ms 4428 KB Output is correct
29 Correct 4 ms 4428 KB Output is correct
30 Correct 4 ms 4456 KB Output is correct
31 Correct 3 ms 4428 KB Output is correct
32 Correct 3 ms 4428 KB Output is correct
33 Correct 3 ms 4428 KB Output is correct
34 Correct 3 ms 4428 KB Output is correct
35 Correct 3 ms 4368 KB Output is correct
36 Correct 4 ms 4428 KB Output is correct
37 Correct 5 ms 4428 KB Output is correct
38 Correct 4 ms 4428 KB Output is correct
39 Correct 4 ms 4372 KB Output is correct
40 Correct 4 ms 4468 KB Output is correct
41 Correct 3 ms 4428 KB Output is correct
42 Correct 3 ms 4428 KB Output is correct
43 Correct 3 ms 4428 KB Output is correct
44 Correct 3 ms 4428 KB Output is correct
45 Correct 3 ms 4428 KB Output is correct
46 Correct 4 ms 4428 KB Output is correct
47 Correct 3 ms 4364 KB Output is correct
48 Correct 4 ms 4372 KB Output is correct
49 Correct 3 ms 4428 KB Output is correct
50 Correct 3 ms 4428 KB Output is correct
51 Correct 3 ms 4428 KB Output is correct
52 Correct 164 ms 17812 KB Output is correct
53 Correct 168 ms 17832 KB Output is correct
54 Correct 162 ms 17816 KB Output is correct
55 Correct 165 ms 17820 KB Output is correct
56 Correct 160 ms 17740 KB Output is correct
57 Correct 164 ms 17864 KB Output is correct
58 Correct 164 ms 17816 KB Output is correct
59 Correct 162 ms 17772 KB Output is correct
60 Correct 161 ms 17768 KB Output is correct
61 Correct 164 ms 17740 KB Output is correct
62 Correct 159 ms 17760 KB Output is correct
63 Correct 162 ms 17752 KB Output is correct
64 Correct 164 ms 17816 KB Output is correct
65 Correct 162 ms 17820 KB Output is correct
66 Correct 162 ms 17760 KB Output is correct
67 Correct 165 ms 17764 KB Output is correct
68 Correct 167 ms 17848 KB Output is correct