답안 #52144

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
52144 2018-06-24T08:15:10 Z evpipis Art Exhibition (JOI18_art) C++14
100 / 100
341 ms 230984 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> ii;

const int len = 5e5+5;
const ll inf = 1e17;
pair<ll, ll> arr[len];
ll pref[len];

int main(){
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
        scanf("%lld %lld", &arr[i].fi, &arr[i].se);
    sort(arr+1, arr+1+n);

    for (int i = 1; i <= n; i++)
        pref[i] = arr[i].se + pref[i-1];

    ll ans = 0, mx = -inf;
    for (int i = n; i >= 1; i--){
        mx = max(mx, pref[i]-arr[i].fi);
        ans = max(ans, mx + arr[i].fi-pref[i-1]);
    }

    printf("%lld\n", ans);
    return 0;
}

Compilation message

art.cpp: In function 'int main()':
art.cpp:16:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
art.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &arr[i].fi, &arr[i].se);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 2 ms 480 KB Output is correct
8 Correct 3 ms 480 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 496 KB Output is correct
11 Correct 3 ms 500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 2 ms 480 KB Output is correct
8 Correct 3 ms 480 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 496 KB Output is correct
11 Correct 3 ms 500 KB Output is correct
12 Correct 3 ms 556 KB Output is correct
13 Correct 2 ms 564 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 740 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 840 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 3 ms 856 KB Output is correct
24 Correct 4 ms 972 KB Output is correct
25 Correct 3 ms 972 KB Output is correct
26 Correct 2 ms 972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 2 ms 480 KB Output is correct
8 Correct 3 ms 480 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 496 KB Output is correct
11 Correct 3 ms 500 KB Output is correct
12 Correct 3 ms 556 KB Output is correct
13 Correct 2 ms 564 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 740 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 840 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 3 ms 856 KB Output is correct
24 Correct 4 ms 972 KB Output is correct
25 Correct 3 ms 972 KB Output is correct
26 Correct 2 ms 972 KB Output is correct
27 Correct 5 ms 1036 KB Output is correct
28 Correct 4 ms 1164 KB Output is correct
29 Correct 4 ms 1292 KB Output is correct
30 Correct 4 ms 1424 KB Output is correct
31 Correct 5 ms 1548 KB Output is correct
32 Correct 5 ms 1688 KB Output is correct
33 Correct 4 ms 1820 KB Output is correct
34 Correct 5 ms 1952 KB Output is correct
35 Correct 5 ms 2080 KB Output is correct
36 Correct 5 ms 2216 KB Output is correct
37 Correct 5 ms 2352 KB Output is correct
38 Correct 4 ms 2480 KB Output is correct
39 Correct 4 ms 2616 KB Output is correct
40 Correct 5 ms 2708 KB Output is correct
41 Correct 5 ms 2848 KB Output is correct
42 Correct 5 ms 2972 KB Output is correct
43 Correct 5 ms 3100 KB Output is correct
44 Correct 5 ms 3236 KB Output is correct
45 Correct 5 ms 3344 KB Output is correct
46 Correct 5 ms 3472 KB Output is correct
47 Correct 5 ms 3604 KB Output is correct
48 Correct 5 ms 3860 KB Output is correct
49 Correct 5 ms 3888 KB Output is correct
50 Correct 5 ms 4024 KB Output is correct
51 Correct 5 ms 4160 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 2 ms 444 KB Output is correct
5 Correct 2 ms 444 KB Output is correct
6 Correct 2 ms 480 KB Output is correct
7 Correct 2 ms 480 KB Output is correct
8 Correct 3 ms 480 KB Output is correct
9 Correct 2 ms 492 KB Output is correct
10 Correct 2 ms 496 KB Output is correct
11 Correct 3 ms 500 KB Output is correct
12 Correct 3 ms 556 KB Output is correct
13 Correct 2 ms 564 KB Output is correct
14 Correct 2 ms 684 KB Output is correct
15 Correct 2 ms 740 KB Output is correct
16 Correct 2 ms 740 KB Output is correct
17 Correct 2 ms 740 KB Output is correct
18 Correct 3 ms 740 KB Output is correct
19 Correct 2 ms 740 KB Output is correct
20 Correct 2 ms 776 KB Output is correct
21 Correct 2 ms 840 KB Output is correct
22 Correct 2 ms 848 KB Output is correct
23 Correct 3 ms 856 KB Output is correct
24 Correct 4 ms 972 KB Output is correct
25 Correct 3 ms 972 KB Output is correct
26 Correct 2 ms 972 KB Output is correct
27 Correct 5 ms 1036 KB Output is correct
28 Correct 4 ms 1164 KB Output is correct
29 Correct 4 ms 1292 KB Output is correct
30 Correct 4 ms 1424 KB Output is correct
31 Correct 5 ms 1548 KB Output is correct
32 Correct 5 ms 1688 KB Output is correct
33 Correct 4 ms 1820 KB Output is correct
34 Correct 5 ms 1952 KB Output is correct
35 Correct 5 ms 2080 KB Output is correct
36 Correct 5 ms 2216 KB Output is correct
37 Correct 5 ms 2352 KB Output is correct
38 Correct 4 ms 2480 KB Output is correct
39 Correct 4 ms 2616 KB Output is correct
40 Correct 5 ms 2708 KB Output is correct
41 Correct 5 ms 2848 KB Output is correct
42 Correct 5 ms 2972 KB Output is correct
43 Correct 5 ms 3100 KB Output is correct
44 Correct 5 ms 3236 KB Output is correct
45 Correct 5 ms 3344 KB Output is correct
46 Correct 5 ms 3472 KB Output is correct
47 Correct 5 ms 3604 KB Output is correct
48 Correct 5 ms 3860 KB Output is correct
49 Correct 5 ms 3888 KB Output is correct
50 Correct 5 ms 4024 KB Output is correct
51 Correct 5 ms 4160 KB Output is correct
52 Correct 256 ms 28516 KB Output is correct
53 Correct 263 ms 41180 KB Output is correct
54 Correct 258 ms 53800 KB Output is correct
55 Correct 257 ms 66404 KB Output is correct
56 Correct 294 ms 79208 KB Output is correct
57 Correct 264 ms 91780 KB Output is correct
58 Correct 274 ms 104464 KB Output is correct
59 Correct 275 ms 117128 KB Output is correct
60 Correct 257 ms 129800 KB Output is correct
61 Correct 261 ms 142312 KB Output is correct
62 Correct 259 ms 154976 KB Output is correct
63 Correct 329 ms 167708 KB Output is correct
64 Correct 286 ms 180396 KB Output is correct
65 Correct 255 ms 193004 KB Output is correct
66 Correct 256 ms 205808 KB Output is correct
67 Correct 341 ms 218280 KB Output is correct
68 Correct 248 ms 230984 KB Output is correct