Mi dice
terminate called after throwing an instance of 'std::length_error'
what(): cannot create std::vector larger than max_size()
con questo input
2
5 5
4 14 14 30 24
-4 +19 -5 +27 +27
10 10
22 14 29 23 22 23 26 6 22 2
+11 +27 +18 -6 +9 -8 -3 -10 +30 -4
ma se lo divido l’input é corretto ovvero
1
5 5
4 14 14 30 24
-4 +19 -5 +27 +27
1
10 10
22 14 29 23 22 23 26 6 22 2
+11 +27 +18 -6 +9 -8 -3 -10 +30 -4
#include <bits/stdc++.h>
using namespace std;
void run_case(int t){
for(int i=0; i<t; i++){
int n, q;
int sum = 0;
bool isHacker = false;
cin >> n >> q;
vector<int> P(n), L(q);
for(int j=0; j<n; j++){
cin >> P[j];
}
for(int j=0; j<q; j++){
cin >> L[j];
if(L[j]>=0){
sum += L[j];
} else {
int index = abs(L[j]) - 1;
if (index < n) {
sum -= P[index];
}
}
if(sum < 0){
isHacker = true;
break;
}
}
cout << (isHacker ? "HACKER" : "OK") << endl;
}
}
int main() {
int t;
cin >> t;
run_case(t);
}