题目链接
!!!注意40%的数据会爆int,所以用long long
#include <iostream>
using namespace std;
int n;
long long sum;
int r,y,g;
int circle;
int nowTime(int b){
long long ti = (sum + b) % circle;
long long ndt = 0;
if(ti < y + r)
ndt = r + y - ti;
return ndt;
}
int main() {
cin>>r>>y>>g;
cin>>n;
circle = r + y + g;
int a,b;
sum = 0;
while (n--){
cin>>a>>b;
if(a == 0){
sum += b;
}
else if(a == 1){
b = r + y - b;
sum += nowTime(b);
}else if(a == 2){
b = y - b;
sum += nowTime(b);
}else if(a == 3) {
b = r + y + g - b;
sum += nowTime(b);
}
}
cout<<sum;
return 0;
}