답안 #4342

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
4342 2013-09-17T09:14:50 Z zorrapower King of penalty (kriii1_K) C++
0 / 1
200 ms 1748 KB
#include<stdio.h>

#define MAX_NUMBER 100000

int main(void){
	long long P;
	long long N;
	long long SolveTime[MAX_NUMBER];
	long long Possible;
	long long PAT=0;
	long long START_TIME;

	scanf("%lld %lld", &P, &N);
	for(int i=0; i<N; i++){
		scanf("%lld", &SolveTime[i]);
	}

	//내림차순 정렬
	for(int i=0; i<N; i++){
		for(int j=i; j<N; j++){
			if(SolveTime[i]>SolveTime[j]){
				long long temp=SolveTime[i];
				SolveTime[i]=SolveTime[j];
				SolveTime[j]=temp;
			}
		}
	}

	long long SUM=0;
	for(int i=0; i<N; i++){
		SUM+=SolveTime[i];
		Possible=i;
		if(SUM>=P){
			i--;
			break;
		}
	}

	printf("%lld\n", Possible);

	START_TIME=P;
	for(int i=0; i<Possible; i++){
		START_TIME-=SolveTime[i];
	}
	START_TIME--;

	PAT+=START_TIME*Possible;
	for(int i=0; i<Possible; i++){
		PAT+=SolveTime[i]*(i+1);
	}

	printf("%lld\n", PAT);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1748 KB Output is correct
2 Correct 0 ms 1744 KB Output is correct
3 Correct 32 ms 1748 KB Output is correct
4 Execution timed out 200 ms 1748 KB Program timed out
5 Halted 0 ms 0 KB -