-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_War.cpp
More file actions
35 lines (34 loc) · 1.19 KB
/
C_War.cpp
File metadata and controls
35 lines (34 loc) · 1.19 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
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const char nl = '\n';
// Author oGhostyyy
/* Thinking: some troy bs , n myrs, i behind i -1 , 0th first , can endure ai
zeus brings them back wtf?
seems obvious so clearly obvious one is TLE, prefix sum to query people dying then binary search correfct prefix?*/
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n; cin >> n; // number of myrmidons
int q; cin >> q; // minutes of battle
vector<ll> a(n); //2* 10*5 mins just spam ll
for(auto& it: a) cin >> it;
vector<ll> prefix(n);
prefix[0] = a[0];
for(int i = 1; i < n; i++) prefix[i] = prefix[i-1] + a[i]; //prefix sum
vector<ll> k(q); //hectors attacks
for(int i = 0; i < q; i++) cin >> k[i];
ll sum = 0;
for(int i = 0; i < q; i++){
sum += k[i];
if(sum >= prefix[n-1]){
// all die just rev
cout << n << nl;
sum = 0;
} else {
//total - fallen , binary search
int fallen = upper_bound(prefix.begin(), prefix.end(), sum) - prefix.begin();//search for first one greater or equal
cout << (n - fallen) << nl;
}
}
}