답안 #1035935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035935 2024-07-26T19:46:12 Z pera 금 캐기 (IZhO14_divide) C++17
100 / 100
67 ms 7748 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 100;
int n , ans = 0 , x[N] , g[N] , e[N] , sum_e[N] , sum_g[N];
void solve(int l , int r){
   if(l > r){
      return;
   }
   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>> u;
   for(int i = l;i <= r;i ++){
      if(i < m){
         u.push_back({sum_e[i - 1] - x[i] , i});
      }else{
         u.push_back({sum_e[i] - x[i] , i});
      }
   }
   sort(u.begin() , u.end());
   int mn = 1e15;
   for(auto [_value , id] : u){
      if(id < m){
         mn = min(mn , sum_g[id - 1]);
      }else{
         ans = max(ans , sum_g[id] - mn);
         if(sum_e[id] - sum_e[m - 1] >= x[id] - x[m]){
            ans = max(ans , sum_g[id] - sum_g[m - 1]);
         }
      }
   }
   for(int i = l;i <= r;i ++){
      sum_e[i] = sum_g[i] = 0;
   }
   solve(l , m - 1);
   solve(m + 1 , r);
}
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] >> e[i];
   }
   x[n + 1] = 1e15;
   x[0] = -1e15;
   solve(1 , n);
   cout << ans << endl;
}

Compilation message

divide.cpp:41:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   41 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 392 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 392 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 392 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 600 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 2 ms 860 KB Output is correct
24 Correct 2 ms 860 KB Output is correct
25 Correct 2 ms 860 KB Output is correct
26 Correct 4 ms 1264 KB Output is correct
27 Correct 5 ms 1248 KB Output is correct
28 Correct 23 ms 4056 KB Output is correct
29 Correct 23 ms 4008 KB Output is correct
30 Correct 53 ms 7744 KB Output is correct
31 Correct 43 ms 7636 KB Output is correct
32 Correct 42 ms 7748 KB Output is correct
33 Correct 46 ms 7740 KB Output is correct
34 Correct 67 ms 7636 KB Output is correct
35 Correct 49 ms 7744 KB Output is correct
36 Correct 43 ms 7740 KB Output is correct