1816: [cqoi2010] poker time limit: 10 sec memory limit: 64 MB
Submit: 1170 solved: 430
[Submit] [Status] Description you have n cards, and the number of card I is CI. There is also a special card: Joker, whose number is M. You can use each card to form a deck, or you can use one joker and one other card to form one deck. For example, when n = 3, there are four valid cards: {1, 2, 3}, {J, 2, 3}, {1, J, 3}, {1, 2, j }. Given n, m, and CI, your task is to form as many cards as possible. Each card can only be used in one deck (a deck can be used but not a deck ). The first line of input contains two integers, N and M, that is, the number of cards and the number of Joker. The second line contains N integer CI, that is, the number of cards for each card. Output outputs only one integer, that is, the maximum number of cards. Sample input3 4
1 2 3 sample output3
Example
The input data indicates that there are 1, 2, 3, and 3 joker in total. Up to three sets of cards can be formed: {1, J, 3}, {J, 2, 3}, {J, 2, 3}. one joker is left, and all other cards are used up.
Data range
50% of data meets the requirements: 2 <= n <= 5, 0 <= m <= 10 ^ 6, 0 <= CI <= 200
100% of the data meets the requirements: 2 <= n <= 50, 0 <= m, CI <= 500,000,000.
Hintsource
Question:
Mom, I read a question for a long time...
The second part + can be determined...
Code:
1 #include<cstdio> 2 3 #include<cstdlib> 4 5 #include<cmath> 6 7 #include<cstring> 8 9 #include<algorithm>10 11 #include<iostream>12 13 #include<vector>14 15 #include<map>16 17 #include<set>18 19 #include<queue>20 21 #include<string>22 23 #define inf 100000000024 25 #define maxn 500+10026 27 #define maxm 500+10028 29 #define eps 1e-1030 31 #define ll long long32 33 #define pa pair<int,int>34 35 #define for0(i,n) for(int i=0;i<=(n);i++)36 37 #define for1(i,n) for(int i=1;i<=(n);i++)38 39 #define for2(i,x,y) for(int i=(x);i<=(y);i++)40 41 #define for3(i,x,y) for(int i=(x);i>=(y);i--)42 43 using namespace std;44 45 inline ll read()46 47 {48 49 ll x=0,f=1;char ch=getchar();50 51 while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1;ch=getchar();}52 53 while(ch>=‘0‘&&ch<=‘9‘){x=10*x+ch-‘0‘;ch=getchar();}54 55 return x*f;56 57 }58 ll n,m,a[55];59 inline bool check(ll x)60 {61 ll t=min(m,x);62 for1(i,n)63 {64 if(a[i]<x)65 {66 t-=x-a[i];67 if(t<0)return 0;68 }69 }70 return 1;71 }72 73 int main()74 75 {76 77 freopen("input.txt","r",stdin);78 79 freopen("output.txt","w",stdout);80 81 n=read();m=read();82 for1(i,n)a[i]=read();83 int l=0,r=inf,mid;84 while(l<=r)85 {86 mid=(l+r)>>1;87 if(check(mid))l=mid+1;else r=mid-1;88 }89 printf("%d\n",r);90 91 return 0;92 93 }View code
Bzoj1816: [cqoi2010] playing cards