Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.3 kB
2
Indexable
Never
#include<iostream>

using namespace std;

int ans;
int used[3];
int duration[3], p[3];
int a[50] , l[50] ;
int n;
int qt[3]; // thoi gian bat dau cua quang cao


void calculate(){
	// tinh toan diem so , luu lai gia tri max
	int point = 0;
	for( int i = 0 ; i < n ; i++){
		int maxPoint = 0;
		for( int j = 0 ; j < 3 ; j++){
			// visitor thu i a[i] l[i]
			// quang cao duration[j] p[j]
			if(qt[j] >= a[i] && qt[j] + duration[j] <= l[i]){
				maxPoint = maxPoint > p[j] ? maxPoint : p[j];
			}
		}
		point += maxPoint;

	}
	ans = ans > point ? ans : point;
}

void Try(int t , int c){

	if( c== 3){
		calculate();
		return;
	}

	if( t > 50) return;

	

	for( int i = 0 ; i < 3; i++){
		if( used[i] == 0){
			used[i] = 1;
			qt[i] = t;
			Try(t+ duration[i] , c+1);
			used[i] = 0;
		}
	}

	Try( t+1,c);
}

int main(){
//	freopen("input.txt","r",stdin);
	int T;
	cin >> T;
	for( int tc = 1 ; tc <= T ;tc++){
		cin >> n;
		for( int j = 0 ; j < 3; j++){
			cin >> duration[j];
		}

		for( int j = 0 ; j < 3 ; j++){
			cin >> p[j];
		}

		for( int i = 0 ; i < n ; i++){
			cin >> a[i];
			int d;
			cin >> d;
			l[i] = a[i] + d;
		}

		ans = 0;
		Try(1,0);
		cout << "Case #" << tc << endl << ans << endl;

	}
	return 0;
}