답안 #123161

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
123161 2019-06-30T09:19:13 Z Hideo Art Exhibition (JOI18_art) C++14
100 / 100
603 ms 150136 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define vl vector < ll >
#define pi pair < int, int >
#define pl pair < ll, ll >
#define pii pair < int, pi >
#define vii vector < pi >

const int N = 5e5 + 7;
const int INF = 1e9 + 7;

pl a[N];
ll st[N][32], pr[N];
ll ans;
int n;

void build (){
    for (int i = 1; i <= 30; i++){
        for (int j = 1; j + (1 << i) - 1 <= n; j++){
            st[j][i] = max(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
        }
    }
}

ll get (int l, int r){
    int pw = log2(r - l + 1);
    return max(st[l][pw], st[r - (1 << pw) + 1][pw]);
}

main(){
    cin >> n;
    for (int i = 1; i <= n; i++)
        scanf("%lld%lld", &a[i].fr, &a[i].sc);
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++)
        pr[i] = pr[i - 1] + a[i].sc;

    for (int i = 1; i <= n; i++)
        st[i][0] = pr[i] - a[i].fr;

    build();
    for (int i = 1; i <= n; i++){
        ans = max(ans, a[i].fr - pr[i - 1] + get(i, n));
    }
    cout << ans;
}

Compilation message

art.cpp:37:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
art.cpp: In function 'int main()':
art.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld%lld", &a[i].fr, &a[i].sc);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 424 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 424 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 6 ms 1912 KB Output is correct
28 Correct 6 ms 1912 KB Output is correct
29 Correct 5 ms 1912 KB Output is correct
30 Correct 6 ms 1912 KB Output is correct
31 Correct 6 ms 1912 KB Output is correct
32 Correct 6 ms 1912 KB Output is correct
33 Correct 6 ms 1784 KB Output is correct
34 Correct 6 ms 1784 KB Output is correct
35 Correct 6 ms 1912 KB Output is correct
36 Correct 6 ms 1912 KB Output is correct
37 Correct 6 ms 1788 KB Output is correct
38 Correct 6 ms 1912 KB Output is correct
39 Correct 6 ms 1784 KB Output is correct
40 Correct 6 ms 1784 KB Output is correct
41 Correct 6 ms 1784 KB Output is correct
42 Correct 7 ms 1912 KB Output is correct
43 Correct 6 ms 1912 KB Output is correct
44 Correct 6 ms 1784 KB Output is correct
45 Correct 6 ms 1912 KB Output is correct
46 Correct 6 ms 1768 KB Output is correct
47 Correct 5 ms 1784 KB Output is correct
48 Correct 6 ms 1784 KB Output is correct
49 Correct 6 ms 1784 KB Output is correct
50 Correct 6 ms 1820 KB Output is correct
51 Correct 6 ms 1784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 4 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 504 KB Output is correct
17 Correct 2 ms 504 KB Output is correct
18 Correct 2 ms 504 KB Output is correct
19 Correct 2 ms 504 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 424 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 504 KB Output is correct
27 Correct 6 ms 1912 KB Output is correct
28 Correct 6 ms 1912 KB Output is correct
29 Correct 5 ms 1912 KB Output is correct
30 Correct 6 ms 1912 KB Output is correct
31 Correct 6 ms 1912 KB Output is correct
32 Correct 6 ms 1912 KB Output is correct
33 Correct 6 ms 1784 KB Output is correct
34 Correct 6 ms 1784 KB Output is correct
35 Correct 6 ms 1912 KB Output is correct
36 Correct 6 ms 1912 KB Output is correct
37 Correct 6 ms 1788 KB Output is correct
38 Correct 6 ms 1912 KB Output is correct
39 Correct 6 ms 1784 KB Output is correct
40 Correct 6 ms 1784 KB Output is correct
41 Correct 6 ms 1784 KB Output is correct
42 Correct 7 ms 1912 KB Output is correct
43 Correct 6 ms 1912 KB Output is correct
44 Correct 6 ms 1784 KB Output is correct
45 Correct 6 ms 1912 KB Output is correct
46 Correct 6 ms 1768 KB Output is correct
47 Correct 5 ms 1784 KB Output is correct
48 Correct 6 ms 1784 KB Output is correct
49 Correct 6 ms 1784 KB Output is correct
50 Correct 6 ms 1820 KB Output is correct
51 Correct 6 ms 1784 KB Output is correct
52 Correct 543 ms 149960 KB Output is correct
53 Correct 546 ms 150136 KB Output is correct
54 Correct 603 ms 150072 KB Output is correct
55 Correct 544 ms 150132 KB Output is correct
56 Correct 539 ms 149984 KB Output is correct
57 Correct 537 ms 149992 KB Output is correct
58 Correct 537 ms 150044 KB Output is correct
59 Correct 574 ms 149980 KB Output is correct
60 Correct 538 ms 150108 KB Output is correct
61 Correct 540 ms 149736 KB Output is correct
62 Correct 560 ms 149856 KB Output is correct
63 Correct 550 ms 149892 KB Output is correct
64 Correct 548 ms 149992 KB Output is correct
65 Correct 537 ms 149988 KB Output is correct
66 Correct 540 ms 150032 KB Output is correct
67 Correct 559 ms 150036 KB Output is correct
68 Correct 532 ms 149912 KB Output is correct