Created
October 13, 2022 17:02
-
-
Save qjatn0120/4e036c071449615beec46b7fdff3f5be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
const int MX = 2e5 + 5; | |
int t, n, q, k, a[MX]; | |
long long int sum[MX]; | |
int main(){ | |
cin.tie(nullptr), ios::sync_with_stdio(false); | |
cin >> t; | |
while(t--){ | |
cin >> n >> q; | |
for(int i = 1; i <= n; i++){ | |
cin >> a[i]; | |
sum[i] = sum[i - 1] + a[i]; | |
a[i] = max(a[i], a[i - 1]); | |
} | |
while(q--){ | |
cin >> k; | |
int lo = 0, hi = n; | |
while(lo < hi){ | |
int mid = (lo + hi + 1) >> 1; | |
if(a[mid] <= k) lo = mid; | |
else hi = mid - 1; | |
} | |
cout << sum[lo] << " "; | |
} | |
cout << "\n"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment