Submission #3558

# Submission time Handle Problem Language Result Execution time Memory
3558 2013-08-31T06:35:24 Z jiyong3 King of penalty (kriii1_K) C++
1 / 1
68 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)
		{
			sum-=(long long)d[solve];
			break;
		}
	}	
	
	int first=p-sum-1;
	long long penalty=(solve>0) ? first : 0;
	long long total=0;

	for(int i=solve-1;i>=0;i--)
	{
		penalty+=(long long)d[i];
		total+=penalty;
	}

	cout << solve << " " << total << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1940 KB Output is correct
2 Correct 0 ms 1940 KB Output is correct
3 Correct 0 ms 1940 KB Output is correct
4 Correct 8 ms 1936 KB Output is correct
5 Correct 0 ms 1936 KB Output is correct
6 Correct 8 ms 1936 KB Output is correct
7 Correct 24 ms 1940 KB Output is correct
8 Correct 24 ms 1936 KB Output is correct
9 Correct 68 ms 1940 KB Output is correct
10 Correct 68 ms 1936 KB Output is correct
11 Correct 32 ms 1936 KB Output is correct
12 Correct 24 ms 1936 KB Output is correct
13 Correct 0 ms 1940 KB Output is correct
14 Correct 4 ms 1936 KB Output is correct
15 Correct 20 ms 1936 KB Output is correct