답안 #1106746

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106746 2024-10-31T02:36:22 Z vjudge1 Art Exhibition (JOI18_art) C++17
100 / 100
192 ms 32328 KB
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define all(lpv) lpv.begin(), lpv.end()
#define fi first
#define se second

using namespace std;

typedef pair<int,int> pii;
const int N = 1e6 + 25;
const int oo = -1e16;
const int mod = 1e9 + 7;

int n, a[N], b[N];

namespace AC{
  int pos[N], s[N], st[N << 1];

  void update(int i,int x){
    i += n - 1;
    st[i] = x;
    while(i > 1){
      i /= 2;
      st[i] = max(st[i << 1], st[i << 1|1]);
    }
  }

  int get(int l,int r){
    if(l > r) return oo;
    r++;
    int ret = oo;
    for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){
      if(l & 1) ret = max(ret, st[l ++]);
      if(r & 1) ret = max(ret, st[-- r]);
    }
    return ret;
  }
  void solve(){
    for(int i = 1; i <= n; i ++) pos[i] = i;
    sort(pos + 1, pos + n + 1, [&](int x,int y){return a[x] < a[y];});
    for(int i = 1; i <= 2 * n; i ++) st[i] = oo;

    for(int t = 1; t <= n; t ++){
      s[t] = s[t - 1] + b[pos[t]];
    }

    int ans = oo;
    update(1, -s[0] + a[pos[1]]);
    for(int t = 1; t <= n; t ++){
      int i = pos[t];
      ans = max(ans, get(1, t) + s[t] - a[pos[t]]);
      update(t + 1, -s[t] + a[pos[t + 1]]);
    }
    cout << ans;
  }
}


signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define task "v"
  if(fopen(task ".inp","r")){
    freopen(task ".inp","r",stdin);
    freopen(task ".out","w",stdout);
  }

  cin >> n;
  for(int i = 1; i <= n; i ++){
    cin >> a[i] >> b[i];
  }
  AC :: solve();

}

Compilation message

art.cpp: In function 'void AC::solve()':
art.cpp:51:11: warning: unused variable 'i' [-Wunused-variable]
   51 |       int i = pos[t];
      |           ^
art.cpp: In function 'int main()':
art.cpp:64:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     freopen(task ".inp","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
art.cpp:65:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     freopen(task ".out","w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6648 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6652 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6648 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6652 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 3 ms 8784 KB Output is correct
28 Correct 3 ms 8784 KB Output is correct
29 Correct 3 ms 8784 KB Output is correct
30 Correct 3 ms 8784 KB Output is correct
31 Correct 3 ms 8784 KB Output is correct
32 Correct 3 ms 8784 KB Output is correct
33 Correct 3 ms 8784 KB Output is correct
34 Correct 4 ms 8784 KB Output is correct
35 Correct 3 ms 8956 KB Output is correct
36 Correct 3 ms 8784 KB Output is correct
37 Correct 3 ms 9016 KB Output is correct
38 Correct 3 ms 8784 KB Output is correct
39 Correct 3 ms 8784 KB Output is correct
40 Correct 3 ms 8784 KB Output is correct
41 Correct 3 ms 8668 KB Output is correct
42 Correct 3 ms 8952 KB Output is correct
43 Correct 3 ms 8784 KB Output is correct
44 Correct 3 ms 8784 KB Output is correct
45 Correct 3 ms 8784 KB Output is correct
46 Correct 3 ms 8784 KB Output is correct
47 Correct 4 ms 8784 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 3 ms 8672 KB Output is correct
50 Correct 3 ms 8796 KB Output is correct
51 Correct 3 ms 8784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6480 KB Output is correct
2 Correct 1 ms 6480 KB Output is correct
3 Correct 1 ms 6480 KB Output is correct
4 Correct 1 ms 6480 KB Output is correct
5 Correct 1 ms 6480 KB Output is correct
6 Correct 1 ms 6480 KB Output is correct
7 Correct 1 ms 6480 KB Output is correct
8 Correct 1 ms 6480 KB Output is correct
9 Correct 1 ms 6480 KB Output is correct
10 Correct 1 ms 6480 KB Output is correct
11 Correct 1 ms 6480 KB Output is correct
12 Correct 1 ms 6480 KB Output is correct
13 Correct 1 ms 6480 KB Output is correct
14 Correct 1 ms 6648 KB Output is correct
15 Correct 1 ms 6480 KB Output is correct
16 Correct 1 ms 6480 KB Output is correct
17 Correct 1 ms 6480 KB Output is correct
18 Correct 1 ms 6480 KB Output is correct
19 Correct 1 ms 6652 KB Output is correct
20 Correct 1 ms 6480 KB Output is correct
21 Correct 1 ms 6480 KB Output is correct
22 Correct 1 ms 6480 KB Output is correct
23 Correct 1 ms 6480 KB Output is correct
24 Correct 1 ms 6480 KB Output is correct
25 Correct 1 ms 6480 KB Output is correct
26 Correct 1 ms 6480 KB Output is correct
27 Correct 3 ms 8784 KB Output is correct
28 Correct 3 ms 8784 KB Output is correct
29 Correct 3 ms 8784 KB Output is correct
30 Correct 3 ms 8784 KB Output is correct
31 Correct 3 ms 8784 KB Output is correct
32 Correct 3 ms 8784 KB Output is correct
33 Correct 3 ms 8784 KB Output is correct
34 Correct 4 ms 8784 KB Output is correct
35 Correct 3 ms 8956 KB Output is correct
36 Correct 3 ms 8784 KB Output is correct
37 Correct 3 ms 9016 KB Output is correct
38 Correct 3 ms 8784 KB Output is correct
39 Correct 3 ms 8784 KB Output is correct
40 Correct 3 ms 8784 KB Output is correct
41 Correct 3 ms 8668 KB Output is correct
42 Correct 3 ms 8952 KB Output is correct
43 Correct 3 ms 8784 KB Output is correct
44 Correct 3 ms 8784 KB Output is correct
45 Correct 3 ms 8784 KB Output is correct
46 Correct 3 ms 8784 KB Output is correct
47 Correct 4 ms 8784 KB Output is correct
48 Correct 3 ms 8796 KB Output is correct
49 Correct 3 ms 8672 KB Output is correct
50 Correct 3 ms 8796 KB Output is correct
51 Correct 3 ms 8784 KB Output is correct
52 Correct 185 ms 32328 KB Output is correct
53 Correct 182 ms 32212 KB Output is correct
54 Correct 184 ms 32228 KB Output is correct
55 Correct 182 ms 32216 KB Output is correct
56 Correct 177 ms 32328 KB Output is correct
57 Correct 179 ms 32328 KB Output is correct
58 Correct 174 ms 32328 KB Output is correct
59 Correct 187 ms 32220 KB Output is correct
60 Correct 192 ms 32220 KB Output is correct
61 Correct 173 ms 32328 KB Output is correct
62 Correct 174 ms 32328 KB Output is correct
63 Correct 182 ms 32328 KB Output is correct
64 Correct 189 ms 32228 KB Output is correct
65 Correct 173 ms 32220 KB Output is correct
66 Correct 173 ms 32216 KB Output is correct
67 Correct 174 ms 32328 KB Output is correct
68 Correct 176 ms 32328 KB Output is correct