답안 #3615

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3615 2013-08-31T07:00:26 Z shinhj88 King of penalty (kriii1_K) C++
0 / 1
200 ms 1236 KB
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int P,N;
vector<int> data;
long long int now;
long long int ans;
void input()
{
	scanf("%d%d",&P,&N);
	data.resize(N);
	for(int i=0;i<N;i++)
	{
		scanf("%d",&data[i]);
	}
	sort(data.begin(),data.end());
	ans=-1;
	now=-1;
	P--;
}
void process(int choose,long long int sum,long long int p,long long int deep)
{
	
	
	for(int i=choose;i<N;i++)
	{
		if(p-data[i]<=0)
		{
			if(deep>=now)
			{
				now=deep;
				ans=max(ans,p*deep+sum);
			}
			return;
		}
		else
		{
			int t=sum+data[i];
			process(i+1,sum+(data[i]*(deep+1)),p-data[i],deep+1);
		}

	}
}
int main()
{
	input();
	process(0,0,P,0);
	printf("%lld %lld\n",now,ans);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 1236 KB Output is correct
2 Correct 0 ms 1236 KB Output is correct
3 Execution timed out 200 ms 1232 KB Program timed out
4 Halted 0 ms 0 KB -