forked from chr4ss1/SPOJ
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAMBM.cpp
More file actions
60 lines (47 loc) · 853 Bytes
/
AMBM.cpp
File metadata and controls
60 lines (47 loc) · 853 Bytes
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
#include <iostream>
#include <string>
#include <vector>
#include <string.h>
#include <map>
#include <queue>
#include <math.h>
#include <algorithm>
#include <iterator>
#include <sstream>
#define SUPERINT unsigned long long
using namespace std;
SUPERINT a[50];
SUPERINT b[50];
int main() {
int t;
scanf("%d", &t);
while(t--){
int K;
SUPERINT N;
SUPERINT exp = 1;
scanf("%llu %d", &N, &K);
for(int j = 0; j < K; j++){
scanf("%llu", &a[j]);
b[j] = (b[j-1] << 1) + a[j];
}
vector<int> wr;
for(int j = K - 1; j >= 0 && N; j--){
if(N >= b[j]){
wr.push_back(j + 1);
N -= b[j];
}
if(N < 0)
break;
}
if(wr.empty() || N){
printf("-1\n");
continue;
}
for(int j = wr.size() - 1; j >= 0; j--){
if(j < wr.size() - 1) printf(" ");
printf("%d", wr[j]);
}
printf("\n");
}
return 0;
}