#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 |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Execution timed out |
200 ms |
1232 KB |
Program timed out |
4 |
Halted |
0 ms |
0 KB |
- |