Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.7 kB
1
Indexable
Never
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#define MAX_SIZE 1000000
#define INF 10000000
using namespace std;

int N, L1, L2, L3, P1, P2, P3;
int timeAdv[5];
int pointAdv[5];
int khach[100][2];
int adv[10] = {0};
int minTime, maxTime;
bool visited[101];
int result;

void reset(){
	for(int i = 0; i < 100; ++i){
		visited[i] = false;
	}
}	

int tinhDiem(){
	int sum = 0;
	for(int i = 0; i < N; ++i){
		int point = 0;
		for(int j = 0; j < 3; ++j){
			if(khach[i][0] <= adv[j] && khach[i][0] + khach[i][1] >= adv[j] + timeAdv[j]){
				if(point < pointAdv[j]){
					point = pointAdv[j];
				}
			}
		}
		sum += point;
	}
	return sum;
}

void backtrack(int k){
	if(k==3){
		for(int i = 0; i < 3; ++i){
			for(int j = 0; j < 3; ++j){
				if(i != j){
					if(timeAdv[i] + adv[i] > adv[j] && timeAdv[i] + adv[i] <= timeAdv[j] + adv[j])
					{
						return;
					}
				}
			}
		}
		int  n = tinhDiem();
		if(n > result){
			result = n;
		}
		return;
	}
	for(int i = 1; i <= 50; ++i){
		adv[k] = i;
		backtrack(k+1);
	}
}

int main(){
	//freopen("input.txt", "r", stdin);
	int T;
	cin >> T;
	for(int tc = 1; tc <= T; ++tc){
		cin >> N;
		for(int i = 0; i < 3; ++i){
			cin >> timeAdv[i];
		}
		for(int i = 0; i < 3; ++i){
			cin >> pointAdv[i];
		}
		minTime = INF;
		maxTime = 0;
		for(int i = 0; i < N; ++i){
			cin >> khach[i][0] >> khach[i][1];
			if(khach[i][0] < minTime){
				minTime = khach[i][0];
			} 
			if(khach[i][1] > maxTime){
				maxTime = khach[i][1];
			}
		}
		for(int i = 0; i < 5; ++i){
			adv[i] = 0;
		}
		result = 0;

		backtrack(0);

		cout << "Case #" << tc << endl << result << endl;
	}

	return 0;
}