#include <iostream> #include <bits/stdc++.h> #include <string> using namespace std; int r,y,g; void change(long long int sum,int &k,int &t)//最开始显示为t秒,sum秒后为什么状态,此时为k灯 { sum%=(r+y+g);///不加此句会超时 if(k==0) return; if(sum-t<0) { t-=sum; return; } else { sum-=t; if(k==1) k=3; else if(k==3) k=2; else if(k==2) k=1; } while(sum>=0)//1--》3--》2 { switch (k) { case 1: if(sum-r<0) { t=r-sum; return; } else { if(k==1) k=3; else if(k==3) k=2; else if(k==2) k=1; sum-=r; } break; case 2: if(sum-y<0) { t=y-sum; return; } else { if(k==1) k=3; else if(k==3) k=2; else if(k==2) k=1; sum-=y; } break; case 3: if(sum-g<0) { t=g-sum; return; } else { if(k==1) k=3; else if(k==3) k=2; else if(k==2) k=1; sum-=g; } break; } } } int main() { cin>>r>>y>>g; int n; cin>>n; long long int sum=0; while(n--) { int k,t; cin>>k>>t; change(sum,k,t); switch (k) { case 0: sum+=t; break; case 1: sum+=t; break; case 2: sum+=(t+r); break; case 3: break; } } cout<<sum<<endl; }