#include <iostream>
#include <algorithm>
using namespace std;
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0);
int N, M;
while(cin >> N >> M){
int round, room[N]={}, T[M], cha[N];
for(int i=0; i<N; i++)
cin >> cha[i];
room[0]= cha[0];
for(int i=1; i<N; i++){
room[i] += room[i-1] + cha[i];
}
round = room[N-1];
for(int i=0; i<M; i++) cin >> T[i];
int pos = 0;
for(int k=0; k<M; k++){
T[k] += room[(pos+N-1)%N];
T[k] %= round;
if(T[k] == 0){
pos = pos;
}
else{
pos = (lower_bound(room, room + N, T[k]) - room) + 1;
}
pos %= N;
}
cout << pos << endl;
}
}
#include
#include
using namespace std;
int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(0);
int N, M;
while(cin >> N >> M){
int round, room[N]={}, T[M], cha[N];
for(int i=0; i<N; i++)
cin >> cha[i];
room[0]= cha[0];
for(int i=1; i<N; i++){
room[i] += room[i-1] + cha[i];
}
round = room[N-1];
for(int i=0; i<M; i++) cin >> T[i];
int pos = 0;
for(int k=0; k<M; k++){
T[k] += room[(pos+N-1)%N];
T[k] %= round;
if(T[k] == 0){
pos = pos;
}
else{
pos = (lower_bound(room, room + N, T[k]) - room) + 1;
}
pos %= N;
}
cout << pos << endl;
}
}
應該是第三個