답안 #654495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654495 2022-10-31T13:46:07 Z ayalla 금 캐기 (IZhO14_divide) C++14
0 / 100
0 ms 212 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long int
#define endl '\n'
#define pb push_back
#define pi pair<int, int>
#define pii pair<int, pi>
#define fir first
#define sec second
#define MAXN 100005
#define mod 1000000007

int n;
vector<pii> v;

bool can(int mid, bool fl)
{
  int j = 0, g = 0, e = 0, ans = 0;
  bool can = 0;
  for (int i = 0; i < n;)
  {
    while (j < n && (v[j].fir - v[i].fir) <= mid)
    {
      g += v[j].sec.fir;
      e += v[j].sec.sec;
      j++;
    }
    int len = v[j - 1].fir - v[i].fir;
    if (e >= len && len >= mid)
    {
      can = 1;
      ans = max(ans, g);
    }
    g -= v[i].sec.fir;
    e -= v[i].sec.sec;
    i = j;
  }
  if (fl)
    cout << ans << endl;
  return can;
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  v.resize(n);
  for (int i = 0; i < n; i++)
    cin >> v[i].fir >> v[i].sec.fir >> v[i].sec.sec;
  sort(v.begin(), v.end());
  int l = 0, r = 1e9 + 2;
  while (l < r)
  {
    int mid = (l + r + 1) >> 1;
    (can(mid, 0)) ? l = mid : r = mid - 1;
  }
  can(l, 1);
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -