답안 #43539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
43539 2018-03-17T12:29:56 Z wxh010910 Art Exhibition (JOI18_art) C++14
100 / 100
283 ms 223240 KB
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define Debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long LL;
typedef long double LD;
typedef unsigned int uint;
typedef pair <int, int> pii;
typedef unsigned long long uLL;

template <typename T> inline void Read(T &x) {
  char c = getchar();
  bool f = false;
  for (x = 0; !isdigit(c); c = getchar()) {
    if (c == '-') {
      f = true;
    }
  }
  for (; isdigit(c); c = getchar()) {
    x = x * 10 + c - '0';
  }
  if (f) {
    x = -x;
  }
}

template <typename T> inline bool CheckMax(T &a, const T &b) {
  return a < b ? a = b, true : false;
}

template <typename T> inline bool CheckMin(T &a, const T &b) {
  return a > b ? a = b, true : false;
}

const int N = 500005;

LL ans, val, a[N], b[N];
int n, p[N];

int main() {
#ifdef wxh010910
  freopen("d.in", "r", stdin);
#endif
  Read(n);
  for (int i = 1; i <= n; ++i) {
    Read(a[i]), Read(b[i]), p[i] = i;
  }
  sort(p + 1, p + n + 1, [&](const int &x, const int &y) {
    return a[x] < a[y];
  });
  for (int i = 1; i <= n; ++i) {
    b[p[i]] += b[p[i - 1]];
    CheckMax(val, a[p[i]] - b[p[i - 1]]);
    CheckMax(ans, val + b[p[i]] - a[p[i]]);
  }
  printf("%lld\n", ans);
#ifdef wxh010910
  Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
#endif
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 496 KB Output is correct
6 Correct 1 ms 532 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 496 KB Output is correct
6 Correct 1 ms 532 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 608 KB Output is correct
13 Correct 2 ms 608 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 2 ms 608 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 2 ms 608 KB Output is correct
18 Correct 1 ms 608 KB Output is correct
19 Correct 2 ms 712 KB Output is correct
20 Correct 1 ms 712 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 712 KB Output is correct
23 Correct 2 ms 712 KB Output is correct
24 Correct 2 ms 712 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 2 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 496 KB Output is correct
6 Correct 1 ms 532 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 608 KB Output is correct
13 Correct 2 ms 608 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 2 ms 608 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 2 ms 608 KB Output is correct
18 Correct 1 ms 608 KB Output is correct
19 Correct 2 ms 712 KB Output is correct
20 Correct 1 ms 712 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 712 KB Output is correct
23 Correct 2 ms 712 KB Output is correct
24 Correct 2 ms 712 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 2 ms 712 KB Output is correct
27 Correct 4 ms 712 KB Output is correct
28 Correct 4 ms 712 KB Output is correct
29 Correct 3 ms 712 KB Output is correct
30 Correct 3 ms 712 KB Output is correct
31 Correct 3 ms 712 KB Output is correct
32 Correct 3 ms 712 KB Output is correct
33 Correct 3 ms 712 KB Output is correct
34 Correct 4 ms 712 KB Output is correct
35 Correct 3 ms 712 KB Output is correct
36 Correct 5 ms 712 KB Output is correct
37 Correct 4 ms 712 KB Output is correct
38 Correct 3 ms 712 KB Output is correct
39 Correct 3 ms 712 KB Output is correct
40 Correct 3 ms 712 KB Output is correct
41 Correct 3 ms 712 KB Output is correct
42 Correct 4 ms 712 KB Output is correct
43 Correct 4 ms 712 KB Output is correct
44 Correct 4 ms 712 KB Output is correct
45 Correct 3 ms 712 KB Output is correct
46 Correct 5 ms 712 KB Output is correct
47 Correct 5 ms 712 KB Output is correct
48 Correct 4 ms 712 KB Output is correct
49 Correct 4 ms 712 KB Output is correct
50 Correct 3 ms 712 KB Output is correct
51 Correct 3 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 1 ms 352 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 1 ms 440 KB Output is correct
5 Correct 1 ms 496 KB Output is correct
6 Correct 1 ms 532 KB Output is correct
7 Correct 2 ms 536 KB Output is correct
8 Correct 2 ms 584 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 1 ms 608 KB Output is correct
13 Correct 2 ms 608 KB Output is correct
14 Correct 1 ms 608 KB Output is correct
15 Correct 2 ms 608 KB Output is correct
16 Correct 2 ms 608 KB Output is correct
17 Correct 2 ms 608 KB Output is correct
18 Correct 1 ms 608 KB Output is correct
19 Correct 2 ms 712 KB Output is correct
20 Correct 1 ms 712 KB Output is correct
21 Correct 2 ms 712 KB Output is correct
22 Correct 2 ms 712 KB Output is correct
23 Correct 2 ms 712 KB Output is correct
24 Correct 2 ms 712 KB Output is correct
25 Correct 2 ms 712 KB Output is correct
26 Correct 2 ms 712 KB Output is correct
27 Correct 4 ms 712 KB Output is correct
28 Correct 4 ms 712 KB Output is correct
29 Correct 3 ms 712 KB Output is correct
30 Correct 3 ms 712 KB Output is correct
31 Correct 3 ms 712 KB Output is correct
32 Correct 3 ms 712 KB Output is correct
33 Correct 3 ms 712 KB Output is correct
34 Correct 4 ms 712 KB Output is correct
35 Correct 3 ms 712 KB Output is correct
36 Correct 5 ms 712 KB Output is correct
37 Correct 4 ms 712 KB Output is correct
38 Correct 3 ms 712 KB Output is correct
39 Correct 3 ms 712 KB Output is correct
40 Correct 3 ms 712 KB Output is correct
41 Correct 3 ms 712 KB Output is correct
42 Correct 4 ms 712 KB Output is correct
43 Correct 4 ms 712 KB Output is correct
44 Correct 4 ms 712 KB Output is correct
45 Correct 3 ms 712 KB Output is correct
46 Correct 5 ms 712 KB Output is correct
47 Correct 5 ms 712 KB Output is correct
48 Correct 4 ms 712 KB Output is correct
49 Correct 4 ms 712 KB Output is correct
50 Correct 3 ms 712 KB Output is correct
51 Correct 3 ms 712 KB Output is correct
52 Correct 283 ms 20360 KB Output is correct
53 Correct 276 ms 33148 KB Output is correct
54 Correct 221 ms 45820 KB Output is correct
55 Correct 222 ms 58400 KB Output is correct
56 Correct 226 ms 71116 KB Output is correct
57 Correct 224 ms 83736 KB Output is correct
58 Correct 201 ms 96412 KB Output is correct
59 Correct 237 ms 109088 KB Output is correct
60 Correct 207 ms 121796 KB Output is correct
61 Correct 238 ms 134568 KB Output is correct
62 Correct 212 ms 147116 KB Output is correct
63 Correct 225 ms 159832 KB Output is correct
64 Correct 249 ms 172408 KB Output is correct
65 Correct 211 ms 185172 KB Output is correct
66 Correct 245 ms 197844 KB Output is correct
67 Correct 231 ms 210528 KB Output is correct
68 Correct 217 ms 223240 KB Output is correct