답안 #654517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
654517 2022-10-31T14:55:21 Z ayalla 금 캐기 (IZhO14_divide) C++14
48 / 100
1000 ms 9676 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

struct item
{
  int pref, sum;
};

vector<item> seg;
vector<int> aux;

item single(int x)
{
  return {x, x};
}
item neutral()
{
  return {0, 0};
}
item merge(item a, item b)
{
  item ret;
  ret.pref = max(a.pref, a.sum + b.pref);
  ret.sum = a.sum + b.sum;
  return ret;
}
void update(int i, int l, int r, int q, int x)
{
  if (l == r)
  {
    seg[i] = single(x);
    return;
  }
  int mid = (l + r) >> 1;
  if (q <= mid)
    update(i << 1, l, mid, q, x);
  else
    update((i << 1) | 1, mid + 1, r, q, x);
  seg[i] = merge(seg[i << 1], seg[(i << 1) | 1]);
}
int query(int l, int r, int i, int x)
{
  if (l == r)
    return l;
  int mid = (l + r) >> 1;
  int curr = seg[i << 1].sum + seg[(i << 1) | 1].pref;
  if (curr >= x)
    return query(mid + 1, r, (i << 1) | 1, x - seg[i << 1].sum);
  if (seg[i << 1].pref < x)
    return -1;
  return query(l, mid, (i << 1), x);
}
void build(int l, int r, int i)
{
  if (l == r)
  {
    seg[i] = single(aux[l]);
    return;
  }
  int mid = (l + r) >> 1;
  build(l, mid, i << 1);
  build(mid + 1, r, (i << 1) | 1);
  seg[i] = merge(seg[i << 1], seg[(i << 1) | 1]);
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<pii> v(n);
  int ans = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> v[i].fir >> v[i].sec.fir >> v[i].sec.sec;
    ans = max(ans, v[i].sec.fir);
  }
  sort(v.begin(), v.end());
  aux.assign(n, 0);
  for (int i = 1; i < n; i++)
  {
    aux[i] = v[i].sec.sec - (v[i].fir - v[i - 1].fir);
  }
  seg.resize(4 * n);
  build(0, n - 1, 1);
  for (int i = 0; i < n; i++)
  {
    int r = query(0, n - 1, 1, -v[i].sec.sec);
    if (r != -1)
    {
      int curr = 0;
      for (int j = i; j <= r; j++)
      {
        curr += v[j].sec.fir;
      }
      ans = max(ans, curr);
    }
    if (i + 1 < n)
      update(1, 0, n - 1, i + 1, 0);
  }
  cout << ans << endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
22 Correct 1 ms 468 KB Output is correct
23 Correct 3 ms 724 KB Output is correct
24 Correct 3 ms 724 KB Output is correct
25 Correct 9 ms 724 KB Output is correct
26 Correct 35 ms 1264 KB Output is correct
27 Correct 35 ms 1256 KB Output is correct
28 Correct 717 ms 5008 KB Output is correct
29 Correct 754 ms 5012 KB Output is correct
30 Execution timed out 1085 ms 9676 KB Time limit exceeded
31 Halted 0 ms 0 KB -