P1855 接水问题

#include<bits/stdc++.h>

using namespace std;

int n,w[11000],m,ans,maxx;

int main(){
    scanf("%d %d",&n,&m);
    for(int i=1;i<=n;i++)
      scanf("%d",&w[i]);
    int t=m+1;
    while(t<=n+1){
        for(int i=1;i<=m;i++){
          w[i]--;
          if(w[i]==0){
             w[i]=w[t];
            t++;
          }
        }
        ans++;
    }
    for(int i=1;i<=m;i++)
        maxx=max(maxx,w[i]);
        
    cout<<ans+maxx<<endl;
}

 

posted @ 2023-05-25 12:29  刘海烽  阅读(96)  评论(0)    收藏  举报