题目链接:http://118.190.20.162/view.page?gpid=T81
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
long long sum=0;
int r,y,g;
int n;
int main(){
cin>>r>>y>>g;
cin>>n;
for(int i=0;i<n;i++){
int sum_cur=sum%(r+g+y);
int k,t;
cin>>k>>t;
if(k==0){
sum=sum+t;
} else if(k==1){
//红灯
//[0,t)-red [t,t+g)-green [t+g,t+g+y)-yellow [t+g+y,r+g+y]-red
if(sum_cur>=0&&sum_cur<t){
sum+=t-sum_cur;
}
else if(sum_cur>=t&&sum_cur<t+g){
sum+=0;
}
else if(sum_cur>=t+g&&sum_cur<t+g+y){
sum+=t+g+y-sum_cur+r;
}
else if(sum_cur>=t+g+y&&sum_cur<=r+g+y){
sum+=r+g+y+t-sum_cur;
}
}
else if(k==2){
//黄灯
//[0,t)-yellow [t,t+r)-red [t+r,t+r+g)-green [t+r+g,r+y+g]
if(sum_cur>=0&&sum_cur<t){
sum+=t-sum_cur+r;
}
else if(sum_cur>=t&&sum_cur<t+r){
sum+=t+r-sum_cur;
}
else if(sum_cur>=t+r&&sum_cur<t+r+g){
sum+=0;
}
else if(sum_cur>=t+r+g&&sum_cur<r+y+g){
sum+=r+y+g+t-sum_cur+r;
}
}
else if(k==3){
//绿灯
//[0,t)-green [t,t+y)-yellow [t+y,t+y+r]-red [t+y+r,r+y+g]-green
if(sum_cur>=0&&sum_cur<t){
sum+=0;
}
else if(sum_cur>=t&&sum_cur<t+y){
sum+=t+y-sum_cur+r;
}
else if(sum_cur>=t+y&&sum_cur<t+y+r){
sum+=t+y+r-sum_cur;
}
else if(sum_cur>=t+y+r&&sum_cur<r+y+g){
sum+=0;
}
}
}
cout<<sum<<endl;
return 0;
}