#include<bits/stdc++.h>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)
#define MOD 1000000007
#define MX 100010
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int tc, kk=1, n, t1, t2, t3, s, p, x, y, person[12];
char ch;
while(cin>>p>>s && p)
{
cin>>t1>>t2>>t3;
cin>>n;
CLR(person);
bool lock[12]={false};
int turn=0;
for(int i=0;i<n;i++)
{
cin>>x>>y;
person[turn]+=x+y;
if(person[turn]==t1 || person[turn]==t2 || person[turn]==t3)
lock[turn]=true;
turn=(turn+1)%p;
while(lock[turn])
{
lock[turn]=false;
turn=(turn+1)%p;
}
}
for(int i=0;i<p;i++)
if(person[i]>s)
{
cout<<i+1<<"\n";
break;
}
}
return 0;
}
No comments:
Post a Comment