답안 #334539

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
334539 2020-12-09T11:02:09 Z Pety 금 캐기 (IZhO14_divide) C++14
100 / 100
36 ms 3180 KB
#include <bits/stdc++.h>

using namespace std;

int n;
int x[100002];
long long g[100002], d[100002], mn[100002];

int cb (int i, long long val) {
  int st = 1, dr = i, ans;
  while (st <= dr) {
    int mij = (st + dr) / 2;
    if (mn[mij] <= val) {
      dr = mij - 1;
      ans = mij;
    }
    else
      st = mij + 1;
  }
  return ans;
}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> x[i] >> g[i] >> d[i];
  long long ans = 0;
  mn[0] = 1e18;
  for (int i = 1; i  <= n; i++) {
    g[i] += g[i - 1];
    d[i] += d[i - 1];
    mn[i] = min(d[i - 1] - x[i], mn[i - 1]);
    int poz = cb(i, d[i] - x[i]);
    ans = max(ans, g[i] - g[poz - 1]);
  }
  ///sum[i] - sum[j - 1] - x[i] + x[j] >= 0
  ///sum[i] - x[i] >= sum[j - 1] - x[j]
  cout << ans;
  return 0;
}

Compilation message

divide.cpp: In function 'int cb(int, long long int)':
divide.cpp:20:10: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   20 |   return ans;
      |          ^~~
divide.cpp: In function 'int main()':
divide.cpp:37:33: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   37 |     ans = max(ans, g[i] - g[poz - 1]);
      |                             ~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 2 ms 492 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 3 ms 640 KB Output is correct
27 Correct 3 ms 620 KB Output is correct
28 Correct 16 ms 1772 KB Output is correct
29 Correct 18 ms 1772 KB Output is correct
30 Correct 36 ms 3052 KB Output is correct
31 Correct 30 ms 3180 KB Output is correct
32 Correct 31 ms 3052 KB Output is correct
33 Correct 28 ms 3052 KB Output is correct
34 Correct 29 ms 3052 KB Output is correct
35 Correct 31 ms 3052 KB Output is correct
36 Correct 32 ms 3052 KB Output is correct