# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3558 | jiyong3 | King of penalty (kriii1_K) | C++98 | 68 ms | 1940 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 <algorithm>
using namespace std;
#define MAXN 100000
int main()
{
int p,n;
int d[MAXN];
cin >> p >> n;
for(int i=0;i<n;i++)
cin >> d[i];
sort(d,d+n);
long long sum=0;
int solve;
for(solve=0;solve<n;solve++)
{
sum+=(long long)d[solve];
if(sum>=p)
{
sum-=(long long)d[solve];
break;
}
}
int first=p-sum-1;
long long penalty=(solve>0) ? first : 0;
long long total=0;
for(int i=solve-1;i>=0;i--)
{
penalty+=(long long)d[i];
total+=penalty;
}
cout << solve << " " << total << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |