답안 #382128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
382128 2021-03-26T12:43:39 Z mohamedsobhi777 금 캐기 (IZhO14_divide) C++14
100 / 100
46 ms 4020 KB
#include <bits/stdc++.h>

using namespace std;

#define vi vector<int>
#define vll vector<ll>
#define vii vector<pair<int, int>>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define loop(_) for (int __ = 0; __ < (_); ++__)
#define pb push_back
#define f first
#define s second
#define sz(_) ((int)_.size())
#define all(_) _.begin(), _.end()
#define lb lower_bound
#define ub upper_bound

using ll = long long;
using ld = long double;

const int N = 1e5 + 7;
const ll mod = 1e9 + 7;

int n;
ll g[N], e[N];
ll x[N];

int main()
{
       ios_base::sync_with_stdio(0);
       cin.tie(0);
#ifndef ONLINE_JUDGE
#endif
       cin >> n;
       ll ans = 0;
       for (int i = 0; i < n; ++i)
       {
              cin >> x[i] >> g[i] >> e[i];
              ans = max(ans, g[i]);
       }
       for (int i = 1; i < n; ++i)
       {
              g[i] += g[i - 1];
              e[i] += e[i - 1];
       }

       vector<int> qu;

       qu.pb(0);

       auto get = [&](int a) -> ll {
              return x[a] - (a ? e[a - 1] : 0);
       };
       for (int i = 1; i < n; ++i)
       {
              ll mv = get(i) - e[i] + e[i - 1];
              int my_cover = partition_point(all(qu), [&](int j) {
                                    return get(j) < mv;
                             }) -
                             qu.begin();
              if (my_cover < sz(qu))
              {
                     int j = qu[my_cover];
                     ans = max(ans, g[i] - (j ? g[j - 1] : 0));
              }
              if (get(i) > get(qu.back()))
              {
                     qu.push_back(i);
              }
       }
       cout << ans;
       return 0;
}
# 결과 실행 시간 메모리 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 492 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 492 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 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 3 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 492 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 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 3 ms 492 KB Output is correct
24 Correct 3 ms 492 KB Output is correct
25 Correct 2 ms 492 KB Output is correct
26 Correct 4 ms 640 KB Output is correct
27 Correct 5 ms 620 KB Output is correct
28 Correct 19 ms 1516 KB Output is correct
29 Correct 23 ms 2288 KB Output is correct
30 Correct 46 ms 3308 KB Output is correct
31 Correct 35 ms 3308 KB Output is correct
32 Correct 35 ms 3308 KB Output is correct
33 Correct 34 ms 3308 KB Output is correct
34 Correct 38 ms 3696 KB Output is correct
35 Correct 40 ms 3952 KB Output is correct
36 Correct 42 ms 4020 KB Output is correct