-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathambm.cpp
More file actions
36 lines (36 loc) · 843 Bytes
/
ambm.cpp
File metadata and controls
36 lines (36 loc) · 843 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
// 2025-05-30
// We don't really need `__int128`. It just makes it easier.
#include <deque>
#include <iostream>
#include <vector>
using namespace std;
void do_testcase() {
long long N; cin >> N;
int K; cin >> K;
vector<long long> a(K);
for (int i = 0; i < K; i++) cin >> a[i];
vector<__int128> b(K);
b[0] = a[0];
for (int i = 1; i < K; i++) {
b[i] = 2*b[i - 1] + a[i];
}
deque<int> result;
for (int i = K - 1; i >= 0; i--) {
if (b[i] <= N) {
result.push_front(i);
N -= b[i];
}
}
if (N > 0) cout << "-1\n";
else {
cout << result[0] + 1;
for (int i = 1; i < result.size(); i++) {
cout << ' ' << result[i] + 1;
}
cout << '\n';
}
}
int main() {
int T; cin >> T;
while (T--) do_testcase();
}