QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#128231#6564. Frequent Flierinstallb#RE 1ms3724kbC++141.0kb2023-07-20 18:57:472023-07-20 18:57:50

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 18:57:50]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3724kb
  • [2023-07-20 18:57:47]
  • 提交

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...

output:


result: