Submission #1298685

#TimeUsernameProblemLanguageResultExecution timeMemory
1298685tabVudu (COCI15_vudu)C++20
42 / 140
1096 ms16684 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); pre.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...