# bzoj1816二分答案 扑克牌

 1 program hehe;
2 var
3  n,m,i,j:longint;
4  c:array[0..50] of longint;
5
6   function min(a,b:longint):longint;
7   begin
8    if a>b then exit(b);
9    exit(a);
10   end;
11
12   function ok(a:longint):boolean;
13   var
14    f,t:longint;
15   begin
16    t:=min(a,m);
17    for f:=1 to n do
18    begin
19     if c[f]<a then
20     t:=t-a+c[f];
21     if t<0 then exit(false);
22    end;
23    exit(true);
24   end;
25
26   function ef(l,r:longint):longint;
27   var
28    mid:longint;
29   begin
30    if l=r then exit(l);
31    mid:=(l+r)>>1;
32    if ok(mid+1) then
33    exit(ef(mid+1,r))
34    else exit(ef(l,mid));
35   end;
36
37 begin
39  for i:=1 to n do read(c[i]);
40  writeln(ef(1,maxlongint-1));
41 end.
View Code

## 1816: [Cqoi2010]扑克牌

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1473  Solved: 566
[Submit][Status][Discuss]

3 4
1 2 3

## Sample Output

3

50%的数据满足：2 < = n < = 5, 0 < = m < = 10^ 6, 0< = ci < = 200
100%的数据满足：2 < = n < = 50, 0 < = m, ci < = 500,000,000。

## Source

[Submit][Status][Discuss]

posted @ 2015-06-16 20:52  ChenThree  阅读(189)  评论(0编辑  收藏  举报