# 29 条题解

• @ 2021-08-30 06:56:04
``````#include <bits/stdc++.h>
using namespace std;

int n,m,w[10001],s[101],maxx;
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>w[i];
for(int i=1;i<=n;i++)
{
maxx=1;
for(int j=2;j<=m;j++)
if(s[maxx]>s[j])
maxx=j;
s[maxx]+=w[i];
}
maxx=1;
for(int i=1;i<=m;i++)
maxx=s[i]>maxx?s[i]:maxx;
cout<<maxx;
return 0;
}
``````
• @ 2018-05-19 09:18:23
``````#include<cstdio>
using namespace std;
int n,m,w[10001],s[101],maxx;//定义
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++) scanf("%d",&w[i]);//输入每个人打水需要的时间
for (int i=1;i<=n;i++)
{
maxx=1;
for (int j=2;j<=m;j++)
if (s[maxx]>s[j])  maxx=j;//找到最小的
s[maxx]+=w[i];//加上他的时间
}
maxx=1;
for (int i=1;i<=m;i++) maxx=s[i]>maxx? s[i]:maxx;//找到最大值
printf("%d",maxx);//输出
}
``````
• @ 2017-11-05 19:43:44

#include<iostream>
#include<queue>
using namespace std;
priority_queue <int,vector<int>,greater<int> > q;
int n,m,w[10005];
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)cin>>w[i];
for(int i=1;i<=m;i++)
{
q.push(w[i]);
}
for(int i=m+1;i<=n;i++)
{
int temp=q.top();
q.pop();
q.push(temp+w[i]);
}
for(int i=1;i<m;i++)q.pop();
cout<<q.top()<<endl;
return 0;
}

• @ 2020-04-12 18:05:19
``````#include <iostream>         //[2010普及组-B]接水问题
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;

int main()
{
int n, m, w;
cin >> n >> m;
priority_queue<int, vector<int>, greater<int>> q;
for (int i = 1; i <= n; i++)
{
cin >> w;
if(i <= m)
q.push(w);
else
{
int k = q.top() + w;
q.pop();
q.push(k);
}
}

while (q.size() > 1)
q.pop();

cout << q.top() << endl;

return 0;
}

``````
• @ 2017-10-27 20:47:31

#include<stdio.h>
int a[10005],n,m,w;
int main()
{
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)
scanf("%d",&a[i]);
for (int i=m+1;i<=n;i++)
{
w=1;
for (int j=2;j<=m;j++)
if (a[w]>a[j]) w=j;
a[w]=a[w]+a[i];
}
w=1;
for (int j=2;j<=m;j++)
if (a[w]<a[j]) w=j;
printf("%d\n",a[w]);
return 0;
}

• @ 2017-09-02 19:50:14

用堆能过更大的数据
const
maxm=80000;
type
node=record
data,num:longint;
end;
var
r:array[1..maxm] of node;
sum:array[1..maxm] of longint;
n,m,i,j,max,w:longint;
procedure heap(n,ii:longint);
var x:node; i,j:longint;
begin
i:=ii;
x:=r[ii];
j:=2*ii;
while j<=n do
begin
if (j<n) and (r[j].data>r[j+1].data) then j:=j+1;
if x.data>r[j].data then begin r[i]:=r[j];i:=j;j:=2*i end
else j:=n+1;
end;
r[i]:=x;
end;
begin
assign(input,'water.in');reset(input);
assign(output,'water.out');rewrite(output);
read(n,m);
max:=1;
for i:=1 to m do
begin
read(r[i].data);
r[i].num:=i;
sum[i]:=r[i].data;
if sum[i]>sum[max] then max:=i;
end;
for i:=m div 2 downto 1 do heap(m,i);
for i:=m+1 to n do
begin
read(w);
r[1].data:=r[1].data+w;
sum[r[1].num]:=sum[r[1].num]+w;
if sum[r[1].num]>sum[max] then max:=r[1].num;
heap(m,1)
end;
writeln(sum[max]);
close(input);close(output);
end.

• @ 2016-12-20 00:00:13

感觉这个测试用例有用
/*
5 3
4 4 15 1 1
*/

• @ 2016-12-19 23:59:35

哈哈 最后一秒Ac了
```c
#include <stdio.h>
int main()
{
int sh[10005];
int n,m;
scanf("%d%d",&n,&m);
int n1 = n;
int index=0;
while(n1--)scanf("%d",&sh[index++]);
int i,j,sum=0;
int max = 0;
if(n <= m)
{
for(i=0; i < m; i++)
{
if(sh[i] > max) max = sh[i];
}
printf("%d\n",max);
return 0;
}
else
{
for(i=m; i<n; i++)
{
int k=0;
for(j=1; j<m; j++)
{
if(sh[j] < sh[k]) k=j;
}
sh[k] += sh[i];
}
int max = 0;
for(i=0; i < m; i++)
{
if(sh[i] > max) max = sh[i];
}
printf("%d\n",max);
}

return 0;
}
/*
5 3
4 4 15 1 1
*/

• @ 2016-10-19 15:40:58
``````#include <iostream>
#include <cstdio>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <algorithm>
#include <time.h>
#include <iomanip>
using namespace std;
int w[10001],a[10001];
int main(){
memset(w,0,sizeof(w));
int n,m;
cin>>n>>m;
if(n<=m){
for(int i=1;i<=n;i++)cin>>w[i];
int sum=w[1];
for(int i=1;i<=n;i++)
if(w[i]>sum)sum=w[i];
cout<<sum<<endl;
}
if(n>m){
int sum=1,tot=0;
for(int i=1;i<=n;i++){
cin>>w[i];
tot+=w[i];
}
for(int i=1;i<=10001;i++)a[i]=w[i];
for(int i=1;i<=tot;i++){
for(int j=1;j<=m;j++){
w[j]--;
if(w[j]==0){
a[j]+=w[m+sum];
w[j]=w[m+sum];
sum++;
}
if(sum>n-m)break;
}if(sum>n-m)break;
}
int b=0;
for(int i=1;i<=n;i++)if(a[i]>b)b=a[i];
cout<<b<<endl;
}
return 0;
}
``````
• @ 2016-09-24 12:41:21
``````#ifndef _DEBUG
#pragma GCC optimize(2)
#ifdef Full_Cpp_Compiler
#include <codecvt>
#endif
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
#include <cstring>
#include <fstream>
#include <Windows.h>
#include <iterator>
#include <set>
#include <process.h>
#include <ctime>
#include <utility>
#include <cctype>
#include <bitset>
#include <stdarg.h>
#define max(a,b) (a>b?a:b)
#define min(a,b) (a>b?a:b)
#endif // _DEBUG
class cmp
{
public:
bool operator()(const int n1, const int n2) const
{
//如果前面的比后面的大，就交换
return n1>n2;
}
};
int main() {
std::ios_base::sync_with_stdio(false);
std::priority_queue<long,std::vector<int>,cmp> time;
int n, m,tmp;

std::cin >> n >> m;

for (int i = 1; i <= m; i++)time.push(0);
for (int i = 1; i <= n; i++) {
std::cin >> tmp;
int t = time.top(); time.pop();
time.push(t + tmp);
}
for (int i = 1; i < m; i++) {
time.pop();
}
std::cout << time.top() << std::endl;
return 0;
}
``````
• @ 2016-05-08 19:59:06

var a:array[1..120]of longint;
i,j,k,mx,m,n,x:longint;
begin
readln(n,m);
for i:=1 to m do read(a[i]);
for i:=m+1 to n do
begin
read(x);
k:=1;
for j:=2 to m do
if a[j]<a[k] then k:=j; a[k]:=a[k]+x; end; mx:=0; for i:=1 to m do if a[i]>mx then mx:=a[i];
writeln(mx);
end.

• @ 2016-05-07 10:48:52

var a:array[1..120]of longint;
i,j,k,mx,m,n,x:longint;
begin
readln(n,m);
for i:=1 to m do read(a[i]);
for i:=m+1 to n do
begin
read(x);
k:=1;
for j:=2 to m do
if a[j]<a[k] then k:=j;
a[k]:=a[k]+x;
end;
mx:=0;
for i:=1 to m do
if a[i]>mx then mx:=a[i];
writeln(mx);
end.

• @ 2016-05-04 16:36:21

var n,m,i,j,k,t:longint;
a:array[0..100]of longint;
begin
readln(n,m);
for i:=1 to m do
begin
read(t);
a[i]:=t;
end;
for i:=m+1 to n do
begin
read(t);
k:=1;
for j:=2 to m do
if a[k]>a[j] then k:=j;
inc(a[k],t);
end;
k:=a[1];
for i:=2 to m do
if k<a[i] then k:=a[i];
writeln(k);
readln;
end.

• @ 2015-11-10 18:34:56

#include<stdio.h>
int w[10005];
int main()
{
int i,j,m,n;
scanf("%d%d",&m,&n);
for (i=1;i<=m;i++)//输入1到m的数据到w[i]
scanf("%d",&w[i]);
for (i=n+1;i<=m;i++)
{
int k=1;//假设w[k]=w[1]是最小
for (j=2;j<=n;j++)
if (w[k]>w[j])
k=j;
w[k]+=w[i];
}
int k=1;
for (i=2;i<=n;i++)
if (w[k]<w[i])
k=i;
printf("%d",w[k]);
return 0;
}

• @ 2015-10-27 21:57:35

这题好水啊 大水题啊！
###Block code
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
priority_queue<int,vector<int>,greater<int> >q;
int n,m,x;
int main()
{
scanf("%d%d",&n,&m);

for(int i=1;i<=m;i++)q.push(0);
for(int i=1;i<=n;i++)
scanf("%d",&x),q.push(q.top()+x),q.pop();
while(q.size()-1)q.pop();
printf("%d\n",q.top());
}

• @ 2015-10-27 08:46:17

编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 536 KiB, score = 10

测试数据 #1: Accepted, time = 1 ms, mem = 536 KiB, score = 10

测试数据 #2: Accepted, time = 1 ms, mem = 536 KiB, score = 10

测试数据 #3: Accepted, time = 0 ms, mem = 536 KiB, score = 10

测试数据 #4: Accepted, time = 1 ms, mem = 536 KiB, score = 10

测试数据 #5: Accepted, time = 1 ms, mem = 536 KiB, score = 10

测试数据 #6: Accepted, time = 1 ms, mem = 536 KiB, score = 10

测试数据 #7: Accepted, time = 2 ms, mem = 548 KiB, score = 10

测试数据 #8: Accepted, time = 0 ms, mem = 576 KiB, score = 10

测试数据 #9: Accepted, time = 3 ms, mem = 576 KiB, score = 10

Accepted, time = 11 ms, mem = 576 KiB, score = 100

代码
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define inf 1e9
using namespace std;
int n,m,a[105];
queue<int>q;
int main()
{
scanf("%d%d",&n,&m);
int x;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
q.push(x);
}
for(int i=1;i<=m;i++)
{
a[i]=q.front();
q.pop();
}
int ans=0,mi,flag=0;
while(true)
{
mi=a[1];
for(int i=2;i<=m;i++)
if(a[i]>0)
mi=min(mi,a[i]);
ans+=mi;
for(int i=1;i<=m;i++)
if(a[i]>0)
a[i]-=mi;

for(int i=1;i<=m;i++)
if(a[i]==0)
{
if(q.size()!=0)
{
a[i]=q.front();
q.pop();
}
else
{
flag=1;
break;
}
}
if(flag)
break;
}
int ma=0;
for(int i=1;i<=m;i++)
ma=max(ma,a[i]);
ans+=ma;
printf("%d",ans);
return 0;

}

• @ 2015-09-05 15:28:16

记录信息
评测状态 Accepted
题目 P1811 接水问题
递交时间 2015-09-05 15:28:01
代码语言 C++
评测机 VijosEx
消耗时间 61 ms
消耗内存 596 KiB
评测时间 2015-09-05 15:28:03
评测结果
编译成功

测试数据 #0: Accepted, time = 1 ms, mem = 596 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 592 KiB, score = 10
测试数据 #2: Accepted, time = 10 ms, mem = 592 KiB, score = 10
测试数据 #3: Accepted, time = 15 ms, mem = 592 KiB, score = 10
测试数据 #4: Accepted, time = 15 ms, mem = 592 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 596 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 596 KiB, score = 10
测试数据 #7: Accepted, time = 2 ms, mem = 596 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 596 KiB, score = 10
测试数据 #9: Accepted, time = 18 ms, mem = 596 KiB, score = 10
Accepted, time = 61 ms, mem = 596 KiB, score = 100
代码
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int got[10005];
int time[10005];
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)
{
scanf("%d",&got[i]);
if(i<=m)time[i]=got[i];
}
int now=m+1;
for(;now<=n;)
{
sort(time+1,time+m+1);
time[1]+=got[now++];
int minn=time[1];
for(int i=2;time[i]<minn&&i<=m;i++)
{
time[i]+=got[now++];
minn=min(minn,time[i]);
}
}
int ans=0;
for(int i=1;i<=m;i++)
ans=max(ans,time[i]);
printf("%d",ans);

}

• @ 2015-09-04 20:35:38

接水问题，水！
var n,m,i,t,f,z:longint;
x,a:array[0..10000]of integer;
begin
read(n,m);t:=1;
for i:=1 to n do begin
read(a[i]);
if i<=m then x[i]:=a[i];
end;
repeat
f:=1;
for i:=1 to m do begin
if x[i]>0 then dec(x[i]);
if x[i]=0 then
if m+t<=n then begin x[i]:=a[m+t];inc(t);end;
end;
inc(z);
for i:=1 to m do
if x[i]<>0 then begin f:=0;break;end;
until f=1;
write(z);
end.

• @ 2015-08-21 14:44:52

#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
int w[10005],mn[10005],i,j,k,l,n,m,q;
bool t[10005],p;
int main()
{
//freopen("water.in","r",stdin);
//freopen("water.out","w",stdout);
cin >>n>>m;
for (i=1;i<=n;i++)
{
cin >>w[i];
mn[i]=i;
}
l=m+1;
while (p==false)
{
j=200;
for (i=1;i<=m;i++)
{
if (w[mn[i]]<j && w[mn[i]]>0) {j=w[mn[i]];q=mn[i];}
}
k=k+j;
for (i=1;i<=m;i++)
{
w[mn[i]]-=j;
if (w[mn[i]]==0)
{
mn[i]=l;
l++;
}
}
p=true;
for (i=1;i<=n;i++)
if (w[i]>0) p=false;
}
cout <<k;
}

• @ 2015-08-18 13:28:12

AC100,不过不知为什么，使用memset在这里无法编译。

include<iostream>
include<cstdio> //#不知道为什么被吃了
int main()
{
using namespace std ;
//freopen("water.in" , "r" , stdin) ;
//freopen("water.out" , "w" , stdout) ;
int n , m , x = 0 ;
cin >> n >> m ;
int stu ;
int a[m + 1] ;

for(int i = 1 ; i <= m ; i++ ) a[i] = 0 ; //数组初始化 存储每个水龙头里存储的水量

for(int i = 1 ; i <= n ; i++ )
{
cin >> stu ;
int min = 1 ;
for(int j = 2 ; j <= m ; j++ )
{

if(a[j] < a[min]) //寻找最少接水量的同学当前位置
min = j ;
}
a[min] += stu ; //水量增加
if(a[min] > x )
{
x = a[min] ; //求出接水最慢的龙头
}
}
cout << x ;
}

• @ 2016-08-06 13:25:22
``````//你的代码
``````
• @ 2016-08-06 13:27:17

要#include<cstring>

ID
1811

4

(无)

1848

783

42%

15