Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
2.7 kB
2
Indexable
Never
package HugoXepLichQuangCao;

import java.io.FileInputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Solution {
    static int n,max_point,start_time,end_time;
    static int[] P,L,A,D,visited,flag;
    static int[][] res;
    public static void main(String[] args) throws Exception {
        System.setIn(new FileInputStream("input.txt"));
        System.setOut(new PrintStream("output.txt"));
        Scanner sc = new Scanner(System.in);
        int tc = sc.nextInt();
        for(int t=1;t<=tc;t++){
            n = sc.nextInt();
            A = new int[n];
            D = new int[n];
            P = new int[4];
            L = new int[4];
            res = new int[4][n];
            visited = new int[4];
            for(int i=1;i<4;i++){
                L[i]=sc.nextInt();
            }
            for(int i=1;i<4;i++){
                P[i]=sc.nextInt();
            }
            for(int i=0;i<n;i++){
                A[i] = sc.nextInt();
                D[i] = sc.nextInt();
            }
            start_time = A[0];
            end_time = A[0]+D[0];
            for(int i=1;i<n;i++){
                start_time = Math.min(start_time, A[i]);
                end_time = Math.max(end_time, A[i]+D[i]);
            }
            max_point = 0;
            BT(0,start_time);
            System.out.println("Case #"+t);
            System.out.println(max_point);
        }
    }
    static void BT(int x,int start){
        if(x==3){
            int sum = 0;
            for(int i=0;i<n;i++){
                int tmp = -1;
                for(int j=1;j<=3;j++){
                    tmp = Math.max(tmp, res[j][i]);
                }
                sum+= tmp;
            }
            max_point = Math.max(max_point,sum);
            return;
        }
        for(int i=1;i<=3;i++){
            if(visited[i]==0){
                if(start>end_time-L[i]){
                    BT(x+1,start);
                }
                else {
                    for(int j= start ;j<=end_time-L[i];j++){
                        int l = j;
                        int r = j+L[i];
                        for(int k=0;k<n;k++){
                            if(A[k]<=l&&A[k]+D[k]>=r){
                                res[i][k] = P[i];
                            }
                        }
                        visited[i] = 1;
                        BT(x+1,j+L[i]);
                        visited[i] = 0;
                        for(int k=0;k<n;k++){
                            res[i][k] = 0;
                        }
                    }
                }
            }
        }
    }
}