QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128231 | #6564. Frequent Flier | installb# | RE | 1ms | 3724kb | C++14 | 1.0kb | 2023-07-20 18:57:47 | 2023-07-20 18:57:50 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=(l);i<=(r);++i)
#define per(i,r,l) for(int i=(r);i>=(l);--i)
using namespace std;
typedef long long ll;
const int N=2e5+10;
int n,m,K,a[N*2],b[N*2],f[N*2];
ll ans;
int gfa(int x){
return f[x]^x?f[x]=gfa(f[x]):x;
}
int main(){
// freopen("in","r",stdin);
scanf("%d%d%d",&n,&m,&K);
int sum=0;
rep(i,1,n) scanf("%d",a+i),f[i]=i;
rep(i,m+1,n+m) f[i]=n;
rep(i,1,n+m){
if(i>m) sum-=b[i-m];
if(sum<n){
int j=i;
while(sum<K){
if(j+m<=i||!j) break;
int t=a[j]-b[j];
if(sum+t>=K){
b[j]+=K-sum;ans+=K-sum;sum=K;
if(b[j]==a[j]) f[j]=j-1;
break;
}
else{
b[j]+=t;ans+=t;sum+=t;
f[j]=j-1;
}
j=gfa(j);
}
}
}
printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3724kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: -100
Runtime Error
input:
200000 2467 999931035 182548858 69876218 33328350 919486767 739850600 948199964 392292320 39077742 366752074 917496841 246661698 37219034 56677740 188278971 965701828 28059790 13200243 825730775 542597589 320715170 939054378 470563899 914247467 990100491 290827128 903662394 611104879 18631185 412134...