Submission #494229

#TimeUsernameProblemLanguageResultExecution timeMemory
494229nickmet2004Bigger segments (IZhO19_segments)C++11
0 / 100
1 ms204 KiB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
int n , a[N];
 main (){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 1; i<= n;++i)cin >> a[i];
    long long x = a[1] , i = 2;
    set<long long> s; int ans = 1;
    while(i <= n){
        long long y =0;
        while(i<=n && x > y + a[i])y+=a[i] , ++i ,s.insert(y);
        y+=a[i];
        //cout << y << " y" << endl;
        if(y>=x)ans++;
        int z = (y - x)/2;
        auto it = s.lower_bound(z);
        if(it != s.end()){
            if(*it == z) y-=z;
            else{
                if(it != s.begin())--it , y-=*it;
            }
        }
        s.clear();
        x = y;
        //cout << x << " x" <<endl;
        ++i;
    }cout << ans;
}

Compilation message (stderr)

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