아직 계정이 없으신가요? 회원가입

Dev. Talk

마이크로 서버 도와주세요

회원사진mswon706
135 views2022-03-22 22:16

가이드 영상 참고하여 아래와 같이 코드를 작성해 보았는데 10점밖에 맞지 못했네요...

혹시 어디서 부족함이 있었을까요? 

도와주세요 고수님들..ㅠ


import java.util.*;
import java.io.*;


public class Main
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        int service[] = new int[901];
        int memSize, server, tmp, start, end;
        StringTokenizer st;
		
        for(int t=0; t<T; t++) {
            server =0;
            memSize=0;
            
            for(int i=300; i<=900; i++){
                service[i] =0;
            }

            int n = Integer.parseInt(br.readLine());
            st = new StringTokenizer(br.readLine());    
            
            for( int i=0; i<n; i++){
                memSize = Integer.parseInt(st.nextToken());
                service[memSize]++;
            }

            for(int i=601 ; i<=900 ; i++){
                server += service[i];
            }

            tmp = getmin(service[300], service[600]);
            server+=tmp;
            service[300]-=tmp;
            service[600]-=tmp;
            server+=service[600];

            start=301;
            end=599;

            while(start<end){
                if(service[start] ==0 ){
                    start++;
                    //continue;
                }else if(service[end] ==0 ){
                    end--;
                    //continue;
                }else if(start+end<=900){
                    tmp = getmin(service[start], service[end]);
                    server+=tmp;
                    service[start]-=tmp;
                    service[end]-=tmp;
                    //continue;
                }else{ // start+end>900
                    server += service[end];
                    end--;
                }
            }

            if(start==end){
                tmp = getmin(service[300], service[end]);
                server +=tmp;
                service[300]-=tmp;
                service[end]-=tmp;

                server +=service[end];
            }

            server+=service[300]/3;
            if(service[300]%3>0){
                server++;
            }

            System.out.println(server);

        }// end tc
    
    }//end main

    static int getmin(int x, int y){
        if(x<=y){
            return x;
        }else{
            return y;
        }
    }
}




import java.util.*;
import java.io.*;


public class Main
{
    public static void main(String args[]) throws IOException
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int T = Integer.parseInt(br.readLine());
        int service[] = new int[901];
        int memSize, server, tmp, start, end;
        StringTokenizer st;
		
        for(int t=0; t<T; t++) {
            server =0;
            memSize=0;
            
            for(int i=300; i<=900; i++){
                service[i] =0;
            }

            int n = Integer.parseInt(br.readLine());
            st = new StringTokenizer(br.readLine());    
            
            for( int i=0; i<n; i++){
                memSize = Integer.parseInt(st.nextToken());
                service[memSize]++;
            }

            for(int i=601 ; i<=900 ; i++){
                server += service[i];
            }

            tmp = getmin(service[300], service[600]);
            server+=tmp;
            service[300]-=tmp;
            service[600]-=tmp;
            server+=service[600];

            start=301;
            end=599;

            while(start<end){
                if(service[start] ==0 ){
                    start++;
                }else if(service[end] ==0 ){
                    end--;
                }else if(start+end<=900){
                    tmp = getmin(service[start], service[end]);
                    server+=tmp;
                    service[start]-=tmp;
                    service[end]-=tmp;
                }else{ // start+end>900

                    if(service[300]>0 && service[300] + service[end]<=900){
                        tmp = getmin(service[300], service[end]);
                        server+=tmp;
                        service[300]-=tmp;
                        service[end]-=tmp;

                        server += service[end];
                        service[end]=0;
                    }else{
                        server += service[end];
                        service[end]=0;
                    }
                }
            }

            if( start==end){

                if( service[end]<=450){
                     tmp=service[end]/2;
                     server+=tmp;
                     service[end]-=tmp*2;
                }

                tmp = getmin(service[300], service[end]);
                server +=tmp;
                service[300]-=tmp;
                service[end]-=tmp;

                server +=service[end];
            }

            server+=service[300]/3;
            if(service[300]%3>0){
                server++;
            }

            System.out.println(server);

        }// end tc
    
    }//end main

    static int getmin(int x, int y){
        if(x<=y){
            return x;
        }else{
            return y;
        }
    }
}