- Time: 2016-03-31-23:49:13 Thursday
- Title Number: [2016-03-31][codeforces][659c][tanya and Toys].md
- The main topic: There are $10^9$ species of goods, the value of the item I, has used n items, to M-yuan, ask the most can buy the number of items not owned
- Analysis: Greedy, from the lowest start to buy, assuming $m = 10^9$, then also buy items not more than $10^6$, because $\frac{(1+k) K}{k} < 10^9$
- Problems encountered: The answer could be 0
#include <algorithm>
#include <cstdio>
using namespace std;
int a[100000 + 10];
int ans[1000000];
int main(){
int n,m;
scanf("%d%d",&n,&m);
for(int i = 0;i < n ; ++i){
scanf("%d",&a[i]);
}
a[n] = 0;
a[n + 1] = 1E9 + 10;
sort(a,a+n+2);
int = 0 ;
for ( int i = 0 i < n + 2 && m > 0 ++ i ) {
for ( int J = a [ i ] + 1 j < a [ i + 1 ] && Span class= "PLN" > m > 0 ;++ j ) {
m -= j;
if(m < 0) break;
ans[cnt++] = j;
}
}
printf("%d\n",cnt);
for(int i = 0;i < cnt;++i){
printf("%d ",ans[i]);
}
printf("\n");
return 0;
}
From for notes (Wiz)
[2016-03-31] [Codeforces] [659C] [Tanya and Toys]