标签:ORC event ios lag open freopen out att stdout
http://codeforces.com/gym/100623/attachments H题
已经给出来的,包括后来添加的,都累加得到ans,那么从1~ans都是可以凑出来的,如果ans<a[now]-1,那么就添加一个ans+1,然后继续操作。
1 #include<iostream> 2 #include<cstdio> 3 #include<queue> 4 #include<algorithm> 5 #include<cmath> 6 #include<ctime> 7 #include<set> 8 #include<map> 9 #include<stack> 10 #include<cstring> 11 #define inf 2147483647 12 #define ls rt<<1 13 #define rs rt<<1|1 14 #define lson ls,nl,mid,l,r 15 #define rson rs,mid+1,nr,l,r 16 #define N 100010 17 #define For(i,a,b) for(long long i=a;i<=b;i++) 18 #define p(a) putchar(a) 19 #define g() getchar() 20 21 using namespace std; 22 23 long long n,m; 24 long long a[400],b[400000]; 25 long long ans,cnt,now; 26 bool flag; 27 void in(long long &x){ 28 long long y=1; 29 char c=g();x=0; 30 while(c<‘0‘||c>‘9‘){ 31 if(c==‘-‘)y=-1; 32 c=g(); 33 } 34 while(c<=‘9‘&&c>=‘0‘){ 35 x=(x<<1)+(x<<3)+c-‘0‘;c=g(); 36 } 37 x*=y; 38 } 39 void o(long long x){ 40 if(x<0){ 41 p(‘-‘); 42 x=-x; 43 } 44 if(x>9)o(x/10); 45 p(x%10+‘0‘); 46 } 47 int main(){ 48 freopen("key.in","r",stdin); 49 freopen("key.out","w",stdout); 50 in(n);in(m); 51 For(i,1,n) 52 in(a[i]); 53 sort(a+1,a+n+1); 54 if(a[1]!=1){ 55 b[++cnt]=1; 56 ans++; 57 m--; 58 } 59 // if(m>0) 60 // For(i,1,n-1){ 61 // ans+=a[i]; 62 // if(ans<a[i+1]-1){ 63 // b[++cnt]=ans+1; 64 // ans+=ans+1; 65 // m--; 66 // } 67 // if(!m) 68 // break; 69 // } 70 now=1; 71 while(m>0){ 72 if(ans<a[now]-1){ 73 b[++cnt]=ans+1; 74 ans+=ans+1; 75 m--; 76 } 77 else{ 78 ans+=a[now]; 79 now++; 80 } 81 if(now>n) 82 break; 83 } 84 while(m>0){ 85 b[++cnt]=ans+1; 86 ans+=ans+1; 87 m--; 88 } 89 For(i,1,cnt) 90 o(b[i]),p(‘ ‘); 91 return 0; 92 }
http://codeforces.com/gym/100623/attachments H题
标签:ORC event ios lag open freopen out att stdout
原文地址:https://www.cnblogs.com/war1111/p/10798556.html