my code is timing out
it is on this problem
here is my code:
#include <bits/stdc++.h>
using namespace std;
int main() {
int piles, howmanyjuicy, juicy, numinpile, sum, juicypile;
vector<int> storeAns;
cin >> piles;
sum = 0;
for(int i = 0; i < piles; i++){
cin >> numinpile;
sum = sum + numinpile;
storeAns.push_back(sum);
}
cin >> howmanyjuicy;
for(int i = 0; i < howmanyjuicy; i++){
cin >> juicy;
juicypile = 0;
for(int k = 0; k < piles; k++){
juicypile++;
if(storeAns[k] >= juicy){
cout << juicypile << "\n";
break;
}
}
}
}
does anyone know how to optimize this