Submission #976957

# Submission time Handle Problem Language Result Execution time Memory
976957 2024-05-07T09:44:12 Z SeenSiravit Vudu (COCI15_vudu) C++14
28 / 140
1000 ms 26288 KB
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const int mxN = 1e6 + 5;

int n;
ll a[mxN] , b[mxN];
ll p;

int main(){
    
    cin>> n;

    for(int i=1;i<=n;i++) cin>> a[i] , a[i] += a[i-1];

    // for(int i=1;i<=n;i++) cout<< a[i] << " ";
    // cout<< "\n";

    cin>> p;

    for(int i=1;i<=n;i++) b[i] = a[i] - p*i;
    // for(int i=1;i<=n;i++) cout<< b[i] << " ";
    // cout<< "\n\n";

    vector<ll> v;

    ll ans = 0;

    for(int i=1;i<=n;i++){
        // cout<< i << " : ";
        // for(auto val : v) cout<< val << " " ;

        int cnt = upper_bound(v.begin() , v.end() , b[i]) - v.begin();

        // cout<< "\ncnt = " << cnt << " ";

        if(a[i]-a[i-1] >= p) cnt++;

        // cout<< cnt << "\n\n";

        ans += cnt;

        v.push_back(b[i-1]);
        sort(v.begin() , v.end());
    }

    cout<< ans;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Execution timed out 1006 ms 2892 KB Time limit exceeded
2 Correct 447 ms 2604 KB Output is correct
3 Correct 520 ms 2600 KB Output is correct
4 Execution timed out 1053 ms 25172 KB Time limit exceeded
5 Execution timed out 1030 ms 16464 KB Time limit exceeded
6 Execution timed out 1014 ms 23344 KB Time limit exceeded
7 Execution timed out 1058 ms 24192 KB Time limit exceeded
8 Execution timed out 1010 ms 22488 KB Time limit exceeded
9 Execution timed out 1020 ms 26288 KB Time limit exceeded
10 Execution timed out 1002 ms 23456 KB Time limit exceeded