# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3501 | solveit | King of penalty (kriii1_K) | C++98 | 24 ms | 2064 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 <iostream>
#include <string>
#include <math.h>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>
using namespace std;
int P, N, A[100005];
int main() {
scanf("%d %d", &P, &N);
for(int i = 1;i<=N;i++)
scanf("%d",&A[i]);
sort(A + 1, A + 1 + N);
A[N + 1] = P;
int S = 0;
long long res = 0;
for(int i = 1;i<=N + 1;i++) {
if(S + A[i] >= P) {
long long acc = 0;
for(int j = i - 1;j>=1;j--) {
acc += A[j];
res += acc;
}
res += ((long long)(P - S - 1)) * (i - 1);
printf("%d %lld\n", i - 1, res);
return 0;
}
S += A[i];
}
printf("%d %d\n", 0, 0);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |