hwangnk1004 / Algorithm

0 stars 0 forks source link

StepByStep #packet #280

Open hwangnk1004 opened 4 years ago

hwangnk1004 commented 4 years ago

import java.util.Scanner;

public class Main { public static void main(String args[]) {

    Scanner scanner = new Scanner(System.in);
    int arr[]=new int[7];
    for(int i=1;i<=6;i++){
        arr[i]=scanner.nextInt();
    }

    int ans=0;
    //size 6
    ans+=arr[6];

    //size 5
    arr[1]-=11*arr[5];
    arr[1] = arr[1] < 0 ? 0 : arr[1];
    ans+=arr[5];

    //size 4
    ans+=arr[4];
    int area = 20*arr[4];
    while(arr[2]>0 && area>0){
        area-=4;
        arr[2]--;
    }
    while(arr[1]>0 && area>0){
        area--;
        arr[1]--;
    }

    //size 3
    int m = arr[3]/4;
    int r = arr[3]%4;
    ans+=m;
    ans+=r>0? 1 : 0;
    if(r>0){
        int p=0, q=0;
        if(r==1){
            p = 4*5;
            q = 1*7;

        }else if(r==2){
            p = 4*3;
            q = 1*6;

        }else if(r==3){
            p= 4*1;
            q= 1*5;
        }

        while(arr[2]>0 && p>0){
            p-=4;
            arr[2]--;
        }
        while(arr[1]>0 && p>0){
            p--;
            arr[1]--;
        }
        while(arr[1]>0 && q>0){
            q--;
            arr[1]--;
        }
    }

    //size 2
    m = arr[2]/9;
    r = arr[2]%9;
    ans+=m;
    ans+=r>0 ? 1:0;
    if(r>0){
        area = 36-r*4;
        while(arr[1]>0 && area>0){
            area--;
            arr[1]--;
        }
    }

    //size 1
    m = arr[1]/36;
    r = arr[1]%36;
    ans+=m;
    ans+=r>0 ? 1 : 0;

    System.out.println(ans);

}

}