# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
384337 | patrikpavic2 | Bigger segments (IZhO19_segments) | C++17 | 159 ms | 21972 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef long long ll;
const int N = 5e5 + 500;
int A[N], n, dp[N];
ll P[N];
priority_queue < pair < pair < ll, ll > , int > > pri;
int main(){
scanf("%d", &n);
for(int i = 0;i < n;i++){
scanf("%d", A + i);
P[i] = A[i] + (i ? P[i - 1] : 0LL);
}
int ndp = 0; ll npr = 0;
for(int i = 0;i < n;i++){
while(!pri.empty() && -pri.top().X.X <= P[i]){
if(pri.top().X.Y > npr){
npr = pri.top().X.Y;
ndp = pri.top().Y;
}
pri.pop();
}
dp[i] = ndp + 1;
pri.push({{-(2LL * P[i] - npr), P[i]}, dp[i]});
}
printf("%d\n", dp[n - 1]);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |