Submission #3613

#TimeUsernameProblemLanguageResultExecution timeMemory
3613MiNuKing of penalty (kriii1_K)C++98
0 / 1
20 ms1936 KiB
#include <iostream> #include <cstdio> #include <algorithm> using namespace std; int main() { int n, p; scanf("%d %d", &p, &n); int t[n+1]; int s = 0; for ( int i=0 ; i<n ; ++i ) { scanf("%d", &t[i]); } sort(t, t+n); int k = 0; for ( int i=0 ; i<n ; ++i ) { if ( s + t[i] < p ) { s += t[i]; ++k; } else { k = i-1; break; } } int e = p - s - 1; long long total = 0LL; for ( int i=k ; i>=0 ; --i ) { e += t[i]; total += e; } printf("%d %lld\n", k+1, total); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...