답안 #1035931

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035931 2024-07-26T19:41:48 Z pera 금 캐기 (IZhO14_divide) C++17
100 / 100
144 ms 15332 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 1;
int n , ans = 0 , SZ;
vector<int> x(N) , g(N) , e(N) , sum_e(N) , sum_g(N) , h(N) , t(N);
void upd(int u , int x){
   assert(u <= SZ);
   while(u <= SZ){
      t[u] = min(t[u] , x);
      u += u&-u;
   }
}
int GET(int u){
   assert(u <= SZ);
   int val = 1e18;
   while(u > 0){
      val = min(val , t[u]);
      u -= u&-u;
   }
   return val;
}
void solve(int l , int r){
   if(l > r){
      return;
   }
   SZ = r - l + 1;
   int m = (l + r) / 2;
   for(int i = l;i <= r;i ++){
      sum_e[i] = sum_e[i - 1] + e[i];
      sum_g[i] = sum_g[i - 1] + g[i];
   }
   vector<pair<int , int>> v , u;
   for(int i = l;i <= r;i ++){
      if(i < m){
         v.push_back({x[i - 1] - sum_e[i - 1] , i});
         u.push_back({sum_e[i - 1] - x[i] , i});
      }else{
         v.push_back({x[i + 1] - sum_e[i] , i});
         u.push_back({sum_e[i] - x[i] , i});
      }
   }
   sort(v.begin() , v.end());
   sort(u.begin() , u.end());
   for(int i = 0;i < (int)u.size();i ++){
      h[u[i].second] = (i == 0 ? 1 : h[u[i - 1].second] + (u[i].first != u[i - 1].first));
   }
   int mn = 1e15;
   for(auto [_value , id] : u){
      //cout << id << " " << h[id] << " " << sum_g[id - 1] << endl;
      if(id < m){
         mn = min(mn , sum_g[id - 1]);
      }else{
         ans = max(ans , sum_g[id] - mn);
         if(x[id + 1] - x[m - 1] >= sum_e[id] - sum_e[m - 1] && sum_e[id] - sum_e[m - 1] > x[id] - x[m]){
            ans = max(ans , sum_g[id] - sum_g[m - 1]);
         }
      }
   }
  // cout << endl;
   for(int i = l;i <= r;i ++){
      sum_e[i] = sum_g[i] = h[i] = 0;
   }
   //cout << l << " " << m << " " << r << " " << mx << endl;
   solve(l , m - 1);
   solve(m + 1 , r);
}
main(){
   cin >> n;
   for(int i = 1;i <= n;i ++){
      cin >> x[i] >> g[i] >> e[i];
      t[i] = 1e18;
   }
   x[n + 1] = 1e10;
   x[0] = -1e9;
   solve(1 , n);
   /*for(int L = 1;L <= n;L ++){
      for(int R = L;R <= n;R ++){
         int s = 0 , se = 0;
         for(int i = L;i <= R;i ++){
            se += e[i];
            s += g[i];
         }
         if(x[R + 1] - x[L - 1] >= se && se > x[R] - x[L]){
            ans = max(ans , s);
         }
      }
   }*/
   cout << ans << endl;
}

Compilation message

divide.cpp:68:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   68 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 3 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 4 ms 5876 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 3 ms 5824 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 3 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 4 ms 5876 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 3 ms 5824 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 3 ms 5980 KB Output is correct
18 Correct 4 ms 5980 KB Output is correct
19 Correct 3 ms 5980 KB Output is correct
20 Correct 3 ms 5980 KB Output is correct
21 Correct 4 ms 5980 KB Output is correct
22 Correct 4 ms 5980 KB Output is correct
23 Correct 7 ms 6236 KB Output is correct
24 Correct 7 ms 6424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5720 KB Output is correct
2 Correct 2 ms 5724 KB Output is correct
3 Correct 2 ms 5724 KB Output is correct
4 Correct 3 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 2 ms 5724 KB Output is correct
7 Correct 4 ms 5876 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 3 ms 5724 KB Output is correct
10 Correct 3 ms 5824 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 2 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 4 ms 5724 KB Output is correct
16 Correct 3 ms 5980 KB Output is correct
17 Correct 3 ms 5980 KB Output is correct
18 Correct 4 ms 5980 KB Output is correct
19 Correct 3 ms 5980 KB Output is correct
20 Correct 3 ms 5980 KB Output is correct
21 Correct 4 ms 5980 KB Output is correct
22 Correct 4 ms 5980 KB Output is correct
23 Correct 7 ms 6236 KB Output is correct
24 Correct 7 ms 6424 KB Output is correct
25 Correct 10 ms 6428 KB Output is correct
26 Correct 13 ms 6768 KB Output is correct
27 Correct 13 ms 6844 KB Output is correct
28 Correct 57 ms 10432 KB Output is correct
29 Correct 59 ms 10564 KB Output is correct
30 Correct 118 ms 15332 KB Output is correct
31 Correct 103 ms 14260 KB Output is correct
32 Correct 111 ms 14260 KB Output is correct
33 Correct 130 ms 14004 KB Output is correct
34 Correct 144 ms 14148 KB Output is correct
35 Correct 116 ms 14516 KB Output is correct
36 Correct 125 ms 14852 KB Output is correct