답안 #1035933

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035933 2024-07-26T19:43:28 Z pera 금 캐기 (IZhO14_divide) C++17
100 / 100
101 ms 7736 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);
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>> 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(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]);
         }
      }
   }
   for(int i = l;i <= r;i ++){
      sum_e[i] = sum_g[i] = 0;
   }
   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];
   }
   x[n + 1] = 1e15;
   x[0] = -1e15;
   solve(1 , n);
   cout << ans << endl;
}

Compilation message

divide.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 3 ms 4184 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 3 ms 4184 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4224 KB Output is correct
13 Correct 2 ms 4184 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4184 KB Output is correct
20 Correct 2 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 6 ms 4444 KB Output is correct
24 Correct 6 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4188 KB Output is correct
2 Correct 2 ms 4184 KB Output is correct
3 Correct 3 ms 4188 KB Output is correct
4 Correct 2 ms 4188 KB Output is correct
5 Correct 2 ms 4188 KB Output is correct
6 Correct 2 ms 4188 KB Output is correct
7 Correct 2 ms 4188 KB Output is correct
8 Correct 2 ms 4188 KB Output is correct
9 Correct 3 ms 4184 KB Output is correct
10 Correct 2 ms 4188 KB Output is correct
11 Correct 2 ms 4188 KB Output is correct
12 Correct 2 ms 4224 KB Output is correct
13 Correct 2 ms 4184 KB Output is correct
14 Correct 2 ms 4188 KB Output is correct
15 Correct 2 ms 4188 KB Output is correct
16 Correct 3 ms 4188 KB Output is correct
17 Correct 3 ms 4188 KB Output is correct
18 Correct 3 ms 4188 KB Output is correct
19 Correct 3 ms 4184 KB Output is correct
20 Correct 2 ms 4188 KB Output is correct
21 Correct 3 ms 4188 KB Output is correct
22 Correct 3 ms 4188 KB Output is correct
23 Correct 6 ms 4444 KB Output is correct
24 Correct 6 ms 4444 KB Output is correct
25 Correct 8 ms 4444 KB Output is correct
26 Correct 8 ms 4700 KB Output is correct
27 Correct 9 ms 4700 KB Output is correct
28 Correct 45 ms 6020 KB Output is correct
29 Correct 49 ms 6056 KB Output is correct
30 Correct 101 ms 7616 KB Output is correct
31 Correct 83 ms 7736 KB Output is correct
32 Correct 85 ms 7732 KB Output is correct
33 Correct 84 ms 7660 KB Output is correct
34 Correct 95 ms 7616 KB Output is correct
35 Correct 88 ms 7632 KB Output is correct
36 Correct 91 ms 7736 KB Output is correct