-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path692B.cpp
More file actions
84 lines (82 loc) · 1.72 KB
/
692B.cpp
File metadata and controls
84 lines (82 loc) · 1.72 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
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
string s;
cin >> s;
vector<int>v;
int m;
cin >> m;
for (int i = 0; i < 10; i++)
{
if(s[i]=='1'){
v.push_back(i+1);
}
}
int arr[1010];
int k = -1;
int n = 0, p = 0;
sort(v.begin(),v.end());
if(v.size()==1 && v[0]==1){
if(m==1){
printf("YES\n");
printf("1\n");
return 0;
}
else
{
printf("NO\n");
return 0;
}
}
if(v.empty()){
printf("NO\n");
return 0;
}
if(v[0]==1){
v[0] = 0;
}
for (int i = 0;; i++)
{
if(i == m)break;
else if(i%2== 0){
bool kau = false;
for(int j = 0; j < v.size(); j++){
if(n+v[j] > p && v[j]!= k){
arr[i] = v[j];
k = v[j];
n += v[j];
kau = true;
break;
}
}
if(!kau){
printf("NO\n");
return 0;
}
}
else if(i%2==1){
bool kau = false;
for(int j = 0; j < v.size(); j++){
if(p+v[j] > n && v[j]!= k){
arr[i] = v[j];
k = v[j];
p += v[j];
kau = true;
// printf("%d\n",p);
break;
}
}
if(!kau){
printf("NO\n");
return 0;
}
}
}
printf("YES\n");
for (int i = 0; i < m; i++)
{
printf("%d ",arr[i]);
}
}