Submission #3615

#TimeUsernameProblemLanguageResultExecution timeMemory
3615shinhj88King of penalty (kriii1_K)C++98
0 / 1
200 ms1236 KiB
#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 timeMemoryGrader output
Fetching results...