Submission #670406

# Submission time Handle Problem Language Result Execution time Memory
670406 2022-12-08T22:14:10 Z illyakr Art Exhibition (JOI18_art) C++14
100 / 100
483 ms 20956 KB
#include <bits/stdc++.h>
#define int long long

using namespace std;

int n;
pair<int, int> t[501010];

int my() {
    sort(t + 1, t + 1 + n, [](pair<int, int> q, pair<int, int> w) {
         return q.first < w.first;
    });
//    cout << endl;
//    for (int i = 1; i <= n; i++)
//        cout << t[i].first << " " << t[i].second << endl;
//        cout << endl;

    int sum = 0;
    int MX = 0;

    int ans = -1010101010101010101;
    for (int i = 1; i <= n; i++) {
        sum += t[i].second;
        ans = max(ans, sum - t[i].first + MX);
        ans = max(ans, t[i].second);
        MX = max(MX, -(sum - t[i].second) + t[i].first);
//        cout << i << " <<< " << -(sum-t[i].second) + t[i].first << endl;
    }
    return ans;
}
int brute() {
    int ans = 0;
    for (int mask = 1; mask < (1 << n); mask++) {
        int cur = 0;
        int MX = 0, MN = 1010101010101010101;
        for (int i = 0; i < n; i++) {
            if (1 & (mask >> i)) {
                cur += t[i + 1].second;
                MX = max(MX, t[i + 1].first);
                MN = min(MN, t[i + 1].first);
            }
        }
        ans = max(ans, cur - MX + MN);
    }
    return ans;
}

int32_t main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
        cin >> t[i].first >> t[i].second;
    cout << my();
//    srand(time(0));
//    for (int id = 1; id <= 10000; id++) {
//        n = rand() % 10 + 1;
//        for (int i = 1; i <= n; i++) {
//            t[i].first = rand() % 10 + 1;
//            t[i].second = rand() % 10 + 1;
//        }
//        int f = my();
//        int s = brute();
//        if (f != s) {
//            cout << n << endl;
//            for (int i = 1; i <= n; i++) {
//                cout << t[i].first << " " << t[i].second << endl;
//            }
//            cout << endl;
//            cout << f << " " << s << endl;
//            exit(1);
//        }
//    }
}

/**
2
7 1
7 2

4 3



5
8 1
7 7
6 5
6 5
1 1

12 16
*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 5 ms 448 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 5 ms 468 KB Output is correct
33 Correct 6 ms 468 KB Output is correct
34 Correct 6 ms 468 KB Output is correct
35 Correct 4 ms 424 KB Output is correct
36 Correct 6 ms 508 KB Output is correct
37 Correct 6 ms 468 KB Output is correct
38 Correct 5 ms 504 KB Output is correct
39 Correct 5 ms 500 KB Output is correct
40 Correct 5 ms 448 KB Output is correct
41 Correct 5 ms 468 KB Output is correct
42 Correct 5 ms 448 KB Output is correct
43 Correct 5 ms 468 KB Output is correct
44 Correct 5 ms 448 KB Output is correct
45 Correct 5 ms 468 KB Output is correct
46 Correct 5 ms 468 KB Output is correct
47 Correct 5 ms 468 KB Output is correct
48 Correct 5 ms 468 KB Output is correct
49 Correct 6 ms 488 KB Output is correct
50 Correct 8 ms 468 KB Output is correct
51 Correct 6 ms 412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 308 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 308 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 212 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 5 ms 468 KB Output is correct
28 Correct 6 ms 504 KB Output is correct
29 Correct 5 ms 448 KB Output is correct
30 Correct 6 ms 468 KB Output is correct
31 Correct 5 ms 468 KB Output is correct
32 Correct 5 ms 468 KB Output is correct
33 Correct 6 ms 468 KB Output is correct
34 Correct 6 ms 468 KB Output is correct
35 Correct 4 ms 424 KB Output is correct
36 Correct 6 ms 508 KB Output is correct
37 Correct 6 ms 468 KB Output is correct
38 Correct 5 ms 504 KB Output is correct
39 Correct 5 ms 500 KB Output is correct
40 Correct 5 ms 448 KB Output is correct
41 Correct 5 ms 468 KB Output is correct
42 Correct 5 ms 448 KB Output is correct
43 Correct 5 ms 468 KB Output is correct
44 Correct 5 ms 448 KB Output is correct
45 Correct 5 ms 468 KB Output is correct
46 Correct 5 ms 468 KB Output is correct
47 Correct 5 ms 468 KB Output is correct
48 Correct 5 ms 468 KB Output is correct
49 Correct 6 ms 488 KB Output is correct
50 Correct 8 ms 468 KB Output is correct
51 Correct 6 ms 412 KB Output is correct
52 Correct 463 ms 20704 KB Output is correct
53 Correct 477 ms 20872 KB Output is correct
54 Correct 456 ms 20748 KB Output is correct
55 Correct 465 ms 20916 KB Output is correct
56 Correct 463 ms 20668 KB Output is correct
57 Correct 460 ms 20692 KB Output is correct
58 Correct 478 ms 20652 KB Output is correct
59 Correct 466 ms 20684 KB Output is correct
60 Correct 483 ms 20868 KB Output is correct
61 Correct 474 ms 20620 KB Output is correct
62 Correct 468 ms 20740 KB Output is correct
63 Correct 461 ms 20748 KB Output is correct
64 Correct 463 ms 20684 KB Output is correct
65 Correct 472 ms 20816 KB Output is correct
66 Correct 465 ms 20736 KB Output is correct
67 Correct 460 ms 20728 KB Output is correct
68 Correct 470 ms 20956 KB Output is correct