http://codeforces.com/gym/100623/attachments H题

时间:2023-03-10 03:25:05
http://codeforces.com/gym/100623/attachments H题

http://codeforces.com/gym/100623/attachments H题
已经给出来的,包括后来添加的,都累加得到ans,那么从1~ans都是可以凑出来的,如果ans<a[now]-1,那么就添加一个ans+1,然后继续操作。

 #include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<set>
#include<map>
#include<stack>
#include<cstring>
#define inf 2147483647
#define ls rt<<1
#define rs rt<<1|1
#define lson ls,nl,mid,l,r
#define rson rs,mid+1,nr,l,r
#define N 100010
#define For(i,a,b) for(long long i=a;i<=b;i++)
#define p(a) putchar(a)
#define g() getchar() using namespace std; long long n,m;
long long a[],b[];
long long ans,cnt,now;
bool flag;
void in(long long &x){
long long y=;
char c=g();x=;
while(c<''||c>''){
if(c=='-')y=-;
c=g();
}
while(c<=''&&c>=''){
x=(x<<)+(x<<)+c-'';c=g();
}
x*=y;
}
void o(long long x){
if(x<){
p('-');
x=-x;
}
if(x>)o(x/);
p(x%+'');
}
int main(){
freopen("key.in","r",stdin);
freopen("key.out","w",stdout);
in(n);in(m);
For(i,,n)
in(a[i]);
sort(a+,a+n+);
if(a[]!=){
b[++cnt]=;
ans++;
m--;
}
// if(m>0)
// For(i,1,n-1){
// ans+=a[i];
// if(ans<a[i+1]-1){
// b[++cnt]=ans+1;
// ans+=ans+1;
// m--;
// }
// if(!m)
// break;
// }
now=;
while(m>){
if(ans<a[now]-){
b[++cnt]=ans+;
ans+=ans+;
m--;
}
else{
ans+=a[now];
now++;
}
if(now>n)
break;
}
while(m>){
b[++cnt]=ans+;
ans+=ans+;
m--;
}
For(i,,cnt)
o(b[i]),p(' ');
return ;
}