# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
4175 | pl0892029 | King of penalty (kriii1_K) | C++98 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
void 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);
}