Submission #3511

# Submission time Handle Problem Language Result Execution time Memory
3511 2013-08-31T06:17:10 Z jiyong3 King of penalty (kriii1_K) C++
0 / 1
0 ms 1940 KB
#include <iostream>
#include <algorithm>
using namespace std;

#define MAXN 100000

int main()
{
	int p,n;
	int d[MAXN];

	cin >> p >> n;
	for(int i=0;i<n;i++)
		cin >> d[i];
	sort(d,d+n);

	long long sum=0;
	int solve;
	for(solve=0;solve<n;solve++)
	{
		sum+=(long long)d[solve];
		if(sum>=p)
			break;
	}
	
	sum-=(long long)d[solve];
	int first=p-sum-1;
	long long penalty=(solve>0) ? first+d[solve-1] : 0;

	for(int i=solve-2;i>=0;i--)
		penalty+=(long long)(penalty+d[i]);

	cout << solve << " " << penalty << endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 1940 KB Output isn't correct
2 Halted 0 ms 0 KB -