# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
3615 | shinhj88 | King of penalty (kriii1_K) | C++98 | 200 ms | 1236 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 <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int P,N;
vector<int> data;
long long int now;
long long int ans;
void input()
{
scanf("%d%d",&P,&N);
data.resize(N);
for(int i=0;i<N;i++)
{
scanf("%d",&data[i]);
}
sort(data.begin(),data.end());
ans=-1;
now=-1;
P--;
}
void process(int choose,long long int sum,long long int p,long long int deep)
{
for(int i=choose;i<N;i++)
{
if(p-data[i]<=0)
{
if(deep>=now)
{
now=deep;
ans=max(ans,p*deep+sum);
}
return;
}
else
{
int t=sum+data[i];
process(i+1,sum+(data[i]*(deep+1)),p-data[i],deep+1);
}
}
}
int main()
{
input();
process(0,0,P,0);
printf("%lld %lld\n",now,ans);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |