답안 #654494

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654494 2022-10-31T13:44:30 Z pauloamed 금 캐기 (IZhO14_divide) C++14
0 / 100
1 ms 1108 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, INT_MAX)){}

  int query(int i){ int ans = INT_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;
}

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];
      e_accu += E[i];
      int I = X[i] - e_accu;
      vals.push_back(I);
    }
  }

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


  int e_accu = 0;
  int g_accu = 0;

  bit.update(idx(vals, 0), 0);

  int ans = INT_MIN;
  for(int i = 0; i < n; ++i){
    e_accu += E[i];
    g_accu += G[i];

    int Ival = X[i] - e_accu;
    int I = idx(vals, Ival);

    // cout << "Ival, I: " << Ival << " " << I << endl;

    int best = bit.query(I);
    bit.update(I, g_accu);

    // cout << "best: " << best << "\n";
    // cout << "g_accu: " << g_accu << endl;

    ans = max(ans, g_accu - best);
    ans = max(ans, G[i]);
  }
  cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1108 KB Output is correct
2 Incorrect 1 ms 1108 KB Output isn't correct
3 Halted 0 ms 0 KB -