P1855 接水问题

lhf123 / 2023-05-25 / 原文

#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;
}