Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m)); }
- template <class T> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n)); }
- template <class T, T init> inline auto vv(int m) { return vector<vector<T>>(m, vector<T>(m, init)); }
- template <class T, T init> inline auto vv(int m, int n) { return vector<vector<T>>(m, vector<T>(n, init)); }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv)
- {
- int t;
- cin >> t;
- while (t--) {
- int n, m;
- cin >> n >> m;
- vector<ll> a(n);
- ll acc = 0;
- vector<ll> pref;
- map<ll, int> cmap;
- for (int i = 0; i < n; ++i) {
- cin >> a[i];
- acc += a[i];
- if (acc >= 0 && (pref.size() == 0 || acc > pref.back())) {
- pref.push_back(acc);
- cmap[acc] = i;
- }
- }
- // dbg(acc);
- ll x;
- for (int i = 0; i < m; ++i) {
- cin >> x;
- int lb = lower_bound(pref.begin(), pref.end(), x) - pref.begin();
- if (lb != pref.size()) {
- // dbg(x, lb, "case 1");
- cout << cmap[pref[lb]] << ' ';
- } else if (acc > 0) {
- ll repeat = x / acc;
- ll delta = x - repeat * acc;
- ll lb = lower_bound(pref.begin(), pref.end(), delta) - pref.begin();
- ll ans = repeat * n + lb;
- if (delta == 0)
- ans -= 1;
- // dbg(repeat, n, delta, lb, ans);
- cout << ans << ' ';
- } else {
- // dbg(x, lb, "case 3");
- cout << -1 << ' ';
- }
- }
- cout << '\n';
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement