Submission #3501

#TimeUsernameProblemLanguageResultExecution timeMemory
3501solveitKing of penalty (kriii1_K)C++98
1 / 1
24 ms2064 KiB
#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 timeMemoryGrader output
Fetching results...