Submission #203965

# Submission time Handle Problem Language Result Execution time Memory
203965 2020-02-23T07:55:01 Z dung11112003 Art Exhibition (JOI18_art) C++11
100 / 100
300 ms 13560 KB
#include <bits/stdc++.h>

#define taskname ""
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex <ld> cd;
typedef vector <cd> vcd;
typedef vector <int> vi;

template<class T> using v2d = vector <vector <T> >;
template<class T> bool uin(T &a, T b)
{
    return a > b ? (a = b, true) : false;
}
template<class T> bool uax(T &a, T b)
{
    return a < b ? (a = b, true) : false;
}

mt19937 rng(chrono::system_clock::now().time_since_epoch().count());

const int maxN = 5e5 + 10;

int n;
struct pic
{
    ll a, b;
    pic() {}
    pic(ll a, ll b) : a(a), b(b) {}
} art[maxN];
ll prefix[maxN];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for1(i, n)
    {
        cin >> art[i].a >> art[i].b;
    }
    sort(art + 1, art + n + 1, [](pic x, pic y)
         {
             return x.a < y.a;
         });
    ll res = 0;
    for1(i, n)
    {
        //set with 1 elements
        uax(res, art[i].b);
    }
    for1(i, n)
    {
        prefix[i] = prefix[i - 1] + art[i].b;
    }
    ll kmax = prefix[n] - art[n].a;
    for (int i = n - 1; i; --i)
    {
        uax(res, kmax - prefix[i] + art[i].a + art[i].b);
        uax(kmax, prefix[i] - art[i].a);
    }
    cout << res;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 400 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 380 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 400 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 380 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 8 ms 632 KB Output is correct
28 Correct 7 ms 636 KB Output is correct
29 Correct 7 ms 632 KB Output is correct
30 Correct 7 ms 632 KB Output is correct
31 Correct 7 ms 632 KB Output is correct
32 Correct 7 ms 632 KB Output is correct
33 Correct 7 ms 632 KB Output is correct
34 Correct 7 ms 632 KB Output is correct
35 Correct 7 ms 632 KB Output is correct
36 Correct 7 ms 632 KB Output is correct
37 Correct 7 ms 632 KB Output is correct
38 Correct 8 ms 632 KB Output is correct
39 Correct 7 ms 632 KB Output is correct
40 Correct 7 ms 632 KB Output is correct
41 Correct 8 ms 632 KB Output is correct
42 Correct 7 ms 632 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 7 ms 632 KB Output is correct
45 Correct 8 ms 632 KB Output is correct
46 Correct 7 ms 632 KB Output is correct
47 Correct 7 ms 632 KB Output is correct
48 Correct 7 ms 632 KB Output is correct
49 Correct 7 ms 632 KB Output is correct
50 Correct 8 ms 632 KB Output is correct
51 Correct 7 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 380 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 6 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 380 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 400 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 380 KB Output is correct
16 Correct 6 ms 376 KB Output is correct
17 Correct 6 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 8 ms 632 KB Output is correct
28 Correct 7 ms 636 KB Output is correct
29 Correct 7 ms 632 KB Output is correct
30 Correct 7 ms 632 KB Output is correct
31 Correct 7 ms 632 KB Output is correct
32 Correct 7 ms 632 KB Output is correct
33 Correct 7 ms 632 KB Output is correct
34 Correct 7 ms 632 KB Output is correct
35 Correct 7 ms 632 KB Output is correct
36 Correct 7 ms 632 KB Output is correct
37 Correct 7 ms 632 KB Output is correct
38 Correct 8 ms 632 KB Output is correct
39 Correct 7 ms 632 KB Output is correct
40 Correct 7 ms 632 KB Output is correct
41 Correct 8 ms 632 KB Output is correct
42 Correct 7 ms 632 KB Output is correct
43 Correct 7 ms 632 KB Output is correct
44 Correct 7 ms 632 KB Output is correct
45 Correct 8 ms 632 KB Output is correct
46 Correct 7 ms 632 KB Output is correct
47 Correct 7 ms 632 KB Output is correct
48 Correct 7 ms 632 KB Output is correct
49 Correct 7 ms 632 KB Output is correct
50 Correct 8 ms 632 KB Output is correct
51 Correct 7 ms 632 KB Output is correct
52 Correct 226 ms 13304 KB Output is correct
53 Correct 225 ms 13432 KB Output is correct
54 Correct 217 ms 13432 KB Output is correct
55 Correct 226 ms 13432 KB Output is correct
56 Correct 228 ms 13304 KB Output is correct
57 Correct 220 ms 13304 KB Output is correct
58 Correct 225 ms 13336 KB Output is correct
59 Correct 218 ms 13432 KB Output is correct
60 Correct 300 ms 13560 KB Output is correct
61 Correct 219 ms 13304 KB Output is correct
62 Correct 215 ms 13304 KB Output is correct
63 Correct 229 ms 13432 KB Output is correct
64 Correct 229 ms 13304 KB Output is correct
65 Correct 226 ms 13504 KB Output is correct
66 Correct 214 ms 13308 KB Output is correct
67 Correct 258 ms 13176 KB Output is correct
68 Correct 229 ms 13176 KB Output is correct