Submission #4176

# Submission time Handle Problem Language Result Execution time Memory
4176 2013-09-03T05:39:52 Z pl0892029 King of penalty (kriii1_K) C++
1 / 1
20 ms 1472 KB
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>

using namespace std;

int main() {
	int p, t, t1;
	int *pt;
	int i, num;
	long long penalty=0, tmp=0, wait; 
	scanf("%d %d", &t, &p);

	pt = (int *)malloc(sizeof(int)*p);
	for(i=0;i<p;i++)
		scanf("%d", &pt[i]);
	
	sort(pt,pt+p);
	i=0;
	t1 = t;
	while(true) {
		t1-=pt[i];
		if(t1<=0 || i==p)
			break;
		penalty+=pt[i];
		i++;
	}
	num=i;
	wait = t-penalty-1;
	for(i=num-1;i>=0;i--) {
		wait+=pt[i];
		tmp+=wait;
	}
	free(pt);
	printf("%d %lld\n", num, tmp); 
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1088 KB Output is correct
2 Correct 0 ms 1088 KB Output is correct
3 Correct 0 ms 1088 KB Output is correct
4 Correct 4 ms 1088 KB Output is correct
5 Correct 0 ms 1088 KB Output is correct
6 Correct 4 ms 1088 KB Output is correct
7 Correct 8 ms 1256 KB Output is correct
8 Correct 12 ms 1276 KB Output is correct
9 Correct 20 ms 1472 KB Output is correct
10 Correct 20 ms 1452 KB Output is correct
11 Correct 12 ms 1472 KB Output is correct
12 Correct 12 ms 1452 KB Output is correct
13 Correct 0 ms 1088 KB Output is correct
14 Correct 0 ms 1088 KB Output is correct
15 Correct 8 ms 1464 KB Output is correct