-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1095C.cpp
More file actions
95 lines (57 loc) · 1.15 KB
/
1095C.cpp
File metadata and controls
95 lines (57 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define INF 1000000000
#define INFL 1000000000000000000
typedef long long ll;
typedef pair <ll, ll> pii;
typedef vector <ll> vi;
bool ligado(ll mask,ll i){
if((mask & (1 << i)) == 0) return false;
return true;
}
int main(){
ll n,m;
cin >> n >> m;
ll mult = 1;
map <ll,ll> cont;
ll maxi = -1;
ll bits = 0;
for(int i=0;i<32;i++){
if(ligado(n,i)){
//cout << "BIT DO " << mult << " LIGADO\ni = " << i << endl;
cont[mult] = 1;
bits++;
if(mult > maxi){
maxi = mult;
}
}
mult *= 2;
}
if(m < bits){
cout << "NO\n";
return 0;
}
while(bits < m && maxi != 1){
cont[maxi]-=1;
cont[maxi/2]+=2;
if(cont[maxi]==0){
maxi = maxi/2;
}
bits++;
}
if(cont[1] == n && m > n){
cout << "NO\n";
return 0;
}
cout << "YES\n";
while(maxi!=0){
for(int i=0;i<cont[maxi];i++){
cout << maxi << " ";
}
maxi = maxi/2;
}
cout << endl;
return 0;
}