1 条题解
-
0
C++ :
/* Date: 26/10/14 10:36 Description:额。。看错题了。。。 个人认为与数据结构有关。 难不成维护区间最小值。。。 个人认为是维护小根堆。 <( ̄▽ ̄)> 哇哈哈… set和时间什么的都去死吧。 1、首先读入前M个,然后每读入一个就修改一次堆顶。 2.然后选堆里面最大的数值。 */ #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<vector> #include<set> #include<queue> using namespace std; priority_queue<int> q1; priority_queue<int ,vector<int>, greater<int> > q; int n,m; int x,y; int ans=0; int main(){ //freopen("water.in","r",stdin); // freopen("water.out","w",stdout); scanf("%d%d",&n,&m); if(n<=m){ for(int i=1;i<=n;++i){ scanf("%d",&x); q1.push(x); } ans=q1.top(); printf("%d",ans); return 0; } else{ for(int i=1;i<=m;++i){ scanf("%d",&x); q.push(x); } int temp=0; for(int i=m+1;i<=n;++i){ scanf("%d",&x); temp=q.top(); q.pop(); q.push(temp+x); } while(!q.empty()){ ans=max(ans,q.top()); q.pop(); } printf("%d",ans); } fclose(stdin); fclose(stdout); }Pascal :
var n,m,i,r,min,j:longint; f:boolean; w:array[1..20000]of integer; begin { assign(input,'water.in'); assign(output,'water.out'); reset(input); rewrite(output);} readln(n,m); for i:=1 to n do read(w[i]); r:=m; repeat min:=min+1; for j:=1 to m do begin if w[j]<>0 then dec(w[j]); if (w[j]=0)and(r<n) then begin inc(r); w[j]:=w[r]; end; end; f:=true; for j:=1 to m do if w[j]<>0 then f:=false; until f and (r=n); writeln(min); {close(input); close(output);} end.
- 1
信息
- ID
- 2588
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者