题目链接
题目大意
学校水房有m个龙头,每个龙头出水量为1。有n位学生接水,顺序已经固定,1到m位同学同时接水,完成需求量Wj时,下一位同学接替接水,接替过程不算时间,求所有同学都接水完的时间。
思路
模拟时间和接水次序即可。
输入与输出
输入
8 4
23 71 87 32 70 93 80 76
输出
163
AC代码
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<queue>
using namespace std;
int n, m;
int f[10005];
int main(int argc, char* argv[])
{
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)scanf("%d", &f[i]);
int idx = m + 1, time = 0;
while (idx <= n + m)
{
for (int i = 1; i <= m; ++i)
{
f[i]--;
if (!f[i])f[i] = f[idx++];
}
time++;
}
printf("%d\n", time);
return 0;
}