CCF CSP201812-2小明放学

在这里插入图片描述
在这里插入图片描述

#include<iostream>
using namespace std;
int main()
{
    
    
	long long int r,g,y,n,k,t,total = 0,alltime;
	cin >> r >> y >>g;
	alltime = r + y + g;
	cin >> n;
	while(n--){
    
    
		int temp = 0;
		cin >> k >> t;
		if(k == 0)
			total += t;
		else if(k == 1){
    
    
			if((total - t ) <= 0)
				total += (t - total);
			else{
    
    
				temp = (total - t) % alltime;
				if(temp >= g && temp <= g + y){
    
    
					total += (y + g - temp + r);
				}
				else if(temp >= g + y){
    
    
					total += (r + g + y - temp);
				}
			}
		}
		else if(k == 2){
    
    
			if((total - t )  <= 0)
				total += (t - total + r);
			else{
    
    
				temp = (total - t) % alltime;
				if(temp <= r){
    
    
					total += (r - temp);
				}
				else if(temp >= r + g && temp <= r + g + y){
    
    
					total += (r + g + y - temp + r);
				}
			}
		}
		else if(k == 3){
    
    
			if((total - t )  < 0)
				continue;
			else{
    
    
				temp = (total - t) % alltime;
				if(temp <= y)
					total += (r + y - temp);
				else if(temp <=  y + r && temp >= y){
    
    
					total += ( y + r - temp);
				}
			}
		}
	}
	cout << total;
}

猜你喜欢

转载自blog.csdn.net/qq_44116998/article/details/108243922