답안 #654513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654513 2022-10-31T14:42:24 Z pauloamed 금 캐기 (IZhO14_divide) C++14
48 / 100
125 ms 13120 KB
#include<bits/stdc++.h>
using namespace std;

#define int long long

const int MAXN = 100000;

struct BIT{
  int n; vector<int> v;
  BIT(int m = 0):n(m + 2), v(vector<int>(n, LLONG_MAX)){}

  int query(int i){ int ans = LLONG_MAX;
    for(i++; i > 0; i -= i & (-i))
      ans = min(ans, v[i]);
    return ans;
  }

  void update(int i, int val){
    for(i++; i < n; i += i & (-i)) 
      v[i] = min(val, v[i]);
  }
};

BIT bit(MAXN);

int X[MAXN], G[MAXN], E[MAXN];

int idx(vector<int> &v, int x){
  int n = v.size();
  int id = lower_bound(v.begin(), v.end(), x) - v.begin();
  return n - 1 - id;
}

int idx(int v[], int i){
  if(i < 0) return 0;
  else return v[i];
}

int32_t main(){
  int n; cin >> n;
  vector<int> vals;

  int e_accu = 0;
  for(int i = 0; i < n; ++i){
    cin >> X[i] >> G[i] >> E[i]; 
    if(i) E[i] += E[i - 1];
    if(i) G[i] += G[i - 1];

    int Iq = X[i] - E[i];
    int Iu = X[i] - idx(E, i - 1);

    vals.push_back(Iq);
    vals.push_back(Iu);
  }

  sort(vals.begin(), vals.end());
  vals.erase(unique(vals.begin(), vals.end()), vals.end());

  int ans = 0;
  for(int i = 0; i < n; ++i){
    int Iq = X[i] - E[i];
    int Iu = X[i] - idx(E, i - 1);

    Iq = idx(vals, Iq);
    Iu = idx(vals, Iu);

    bit.update(Iu, idx(G, i - 1));
    int best = bit.query(Iq);


    ans = max(ans, G[i] - best);
  }
  cout << ans << "\n";
}

Compilation message

divide.cpp: In function 'int32_t main()':
divide.cpp:43:7: warning: unused variable 'e_accu' [-Wunused-variable]
   43 |   int e_accu = 0;
      |       ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 2 ms 1108 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 2 ms 1108 KB Output is correct
17 Correct 3 ms 1108 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 2 ms 1108 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 3 ms 1252 KB Output is correct
23 Correct 6 ms 1492 KB Output is correct
24 Correct 7 ms 1496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Correct 1 ms 1108 KB Output is correct
3 Correct 1 ms 1108 KB Output is correct
4 Correct 1 ms 1108 KB Output is correct
5 Correct 1 ms 1108 KB Output is correct
6 Correct 1 ms 1108 KB Output is correct
7 Correct 1 ms 1100 KB Output is correct
8 Correct 1 ms 1108 KB Output is correct
9 Correct 1 ms 1108 KB Output is correct
10 Correct 1 ms 1108 KB Output is correct
11 Correct 1 ms 1108 KB Output is correct
12 Correct 1 ms 1108 KB Output is correct
13 Correct 2 ms 1108 KB Output is correct
14 Correct 1 ms 1100 KB Output is correct
15 Correct 2 ms 1108 KB Output is correct
16 Correct 2 ms 1108 KB Output is correct
17 Correct 3 ms 1108 KB Output is correct
18 Correct 4 ms 1116 KB Output is correct
19 Correct 2 ms 1108 KB Output is correct
20 Correct 2 ms 1108 KB Output is correct
21 Correct 3 ms 1116 KB Output is correct
22 Correct 3 ms 1252 KB Output is correct
23 Correct 6 ms 1492 KB Output is correct
24 Correct 7 ms 1496 KB Output is correct
25 Correct 6 ms 1500 KB Output is correct
26 Correct 9 ms 1752 KB Output is correct
27 Correct 14 ms 1760 KB Output is correct
28 Correct 57 ms 4172 KB Output is correct
29 Correct 73 ms 4604 KB Output is correct
30 Runtime error 125 ms 13120 KB Execution killed with signal 11
31 Halted 0 ms 0 KB -