codeforces #346 div 2 C. Tanya and Toys (暴力乱搞)
题目链接 题意:有1E9个礼物,第i个礼物价钱是i,然后现在已经有n个不重复的礼物,a[i],m元钱,想尽可能多得买不同种类的礼物,还能买多少个。 思路:先不考虑已经买的,从1连续买到k,然后考虑子啊这个区间内已经买的,等于实际上没有花钱。 反正就是暴力搞啊搞啊。。我也不知道怎么搞。。 结果最后。。方案数为0的时候。。。最后一个答案我是单独输出的。。忘了判断了。。。所以会输出两个0.宝宝心里苦啊。。。。。。。。
/* ***********************************************
Author :111qqz
Created Time :2016年03月31日 星期四 00时00分03秒
File Name :code/cf/#346/C.cpp
************************************************ */
1#include <cstdio>
2#include <cstring>
3#include <iostream>
4#include <algorithm>
5#include <vector>
6#include <queue>
7#include <set>
8#include <map>
9#include <string>
10#include <cmath>
11#include <cstdlib>
12#include <ctime>
13#define fst first
14#define sec second
15#define lson l,m,rt<<1
16#define rson m+1,r,rt<<1|1
17#define ms(a,x) memset(a,x,sizeof(a))
18typedef long long LL;
19#define pi pair < int ,int >
20#define MP make_pair
1using namespace std;
2const double eps = 1E-8;
3const int dx4[4]={1,0,0,-1};
4const int dy4[4]={0,-1,1,0};
5const int inf = 0x3f3f3f3f;
6const int N=3E5+7;
7LL n,m;
8LL a[N];
9LL sum[N];
10set<LL>se;
11LL ans[N];
12bool vis[N];
13int main()
14{
15 #ifndef ONLINE_JUDGE
16 freopen("code/in.txt","r",stdin);
17 #endif
18 ms(vis,false);
19// ios::sync_with_stdio(false); //注意这题可能会爆long long
20 cin>>n>>m;
21 sum[0] = 0LL;
22 for ( int i = 1 ; i <= n ;i++)
23 {
24 cin>>a[i];
25 sum[i] = sum[i-1] + a[i];
26 se.insert(a[i]);
27 }
sort(a+1,a+n+1);
1 LL k;
2 for ( LL i =1 ; ; i++)
3 {
4 LL tmp =i*(i+1)/2;
5 if (tmp>m)
6 {
7 k = i-1;
8 break;
9 }
10 vis[i] = true;
11 }
12 LL cost = k*(k+1)/2;
13// cout<<"k:"<<k<<endl;
14 for ( int i = 1 ; i <= n ; i++)
15 {
16 if (a[i]<=k)
17 {
18 cost -= a[i];
19 vis[a[i]] = false;
20 }
21 else
22 break;
23 }
1// cout<<"cost:"<<cost<<endl;
2// LL res = m-cost;
3// cout<<"res:"<<res<<endl;
1 for ( LL i = k; ; i++)
2 {
3 if (se.count(i+1)) continue;
4 cost = cost + i + 1;
5 if (cost>m)
6 {
7 k = i;
8 break;
9 }
10 vis[i+1] =true;
}
1 ms(ans,0LL);
2// cout<<"k:"<<k<<endl;
3 int cnt = 0 ;
4 for ( int i = 1 ; i <= k ; i++)
5 {
6 if (vis[i])
7 {
8 cnt++;
9 ans[cnt] = i;
10 }
11 }
12 cout<<cnt<<endl;
13 for ( int i = 1 ; i < cnt ; i++) cout<<ans[i]<<" ";
14 if (cnt!=0)
15 cout<<ans[cnt];
1 #ifndef ONLINE_JUDGE
2 fclose(stdin);
3 #endif
4 return 0;
5}