Submission #444881

#TimeUsernameProblemLanguageResultExecution timeMemory
444881JovanBDivide and conquer (IZhO14_divide)C++17
100 / 100
43 ms7324 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
ll g[100005];
ll x[100005];
ll d[100005];
ll xx[100005];
 
int main(){
    ios_base::sync_with_stdio(false);
 
    int n;
    cin >> n;
    vector <pair <ll, int>> tren;
    ll sum = 0;
    for(int i=1; i<=n; i++){
        cin >> xx[i] >> g[i] >> d[i];
        x[i] = xx[i]-xx[1];
        g[i] += g[i-1];
        d[i] += d[i-1];
        sum = max(sum, g[i]-g[i-1]);
        int l=0, r=tren.size()-1, j=i;
        while(l <= r){
            int mid = (l+r)/2;
            if(tren[mid].first-x[i]+d[i] >= 0){
                r = mid-1;
                j = mid;
            }
            else l = mid+1;
        }
        if(j < tren.size()) sum = max(sum, g[i]-g[tren[j].second-1]);
        if(tren.empty() || tren.back().first < x[i]-d[i-1]) tren.push_back({x[i]-d[i-1], i});
    }
    cout << sum << "\n";
    return 0;
}

Compilation message (stderr)

divide.cpp: In function 'int main()':
divide.cpp:33:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |         if(j < tren.size()) sum = max(sum, g[i]-g[tren[j].second-1]);
      |            ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...