Submission #1298684

#TimeUsernameProblemLanguageResultExecution timeMemory
1298684tabVudu (COCI15_vudu)C++20
42 / 140
702 ms9788 KiB
#include "bits/stdc++.h"
using namespace std;
#define intt long long
#define fi first
#define se second

const intt mxN = 1e5 + 5;
const intt LG = 20;
const intt inf = 1e18;  
const intt mod = 10007;

intt n, p;
vector<intt> a(mxN), pre(mxN);
multiset<intt> mst;


void _() {
    cin >> n;
    a.resize(n);
    for(intt i = 0; i < n; i++) {
        cin >> a[i];
        pre[i] = a[i];
        if(i) pre[i] += pre[i-1];
    }
    cin >> p;
    
    mst.insert(pre[0]);
    intt ans = 0;
    for(intt i = 1; i < n; i++) {
        // cout << i << ": ";
        // for(intt popo : mst) cout << popo << " ";
        // cout << endl;
        intt l = 0, r = (intt)mst.size()-1, best = 0;
        while(l <= r) {
            intt mid = (l + r) / 2;
            intt m = mid;
            auto it = mst.begin();
            while(m--) ++it;

            // cout << l << " " << mid << " " << r << " " << *it << endl;
            if(*it <= pre[i] - (p * i)) {
                best = mid+1;
                l = mid + 1;
            } else {
                r = mid - 1;
            }
        }
        ans += best;
        mst.insert(pre[i] - (p * i));
    }
    for(intt i = 0; i < n; i++) {
        // cout << pre[i] << " " << pre[i] / (i + 1) << endl;
        if(pre[i] / (i + 1) >= p) {
            ans++;
        }
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    intt t = 1, buu = 1;
    // cin >> t;
    while(t--){
        // cout << "Case #" << buu++ << ": ";
        _();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...