제출 #1035933

#제출 시각아이디문제언어결과실행 시간메모리
1035933peraDivide and conquer (IZhO14_divide)C++17
100 / 100
101 ms7736 KiB
#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; }

컴파일 시 표준 에러 (stderr) 메시지

divide.cpp:43:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   43 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...