#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> ls;
int main(void){
int n,p;
scanf("%d %d",&p,&n);
ls.clear();
for(int i = 0 ; i< n;i++)
{
int a;
scanf("%d",&a);
ls.push_back(a);
}
sort(ls.begin(),ls.end());
int cnt= 0;
long long sum = 0;
p--;
for(int i = 0 ;i < ls.size();i++)
{
if( p - ls[i] >= 0 )
{
sum += p;
p -= ls[i];
cnt++;
}
}
printf("%d %lld\n",cnt, sum);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
1672 KB |
Output is correct |
2 |
Correct |
0 ms |
1672 KB |
Output is correct |
3 |
Correct |
0 ms |
1672 KB |
Output is correct |
4 |
Correct |
0 ms |
1804 KB |
Output is correct |
5 |
Correct |
0 ms |
1672 KB |
Output is correct |
6 |
Correct |
4 ms |
1804 KB |
Output is correct |
7 |
Correct |
4 ms |
2060 KB |
Output is correct |
8 |
Correct |
12 ms |
2060 KB |
Output is correct |
9 |
Correct |
24 ms |
2444 KB |
Output is correct |
10 |
Correct |
16 ms |
2444 KB |
Output is correct |
11 |
Correct |
16 ms |
2444 KB |
Output is correct |
12 |
Correct |
12 ms |
2444 KB |
Output is correct |
13 |
Correct |
0 ms |
1672 KB |
Output is correct |
14 |
Correct |
0 ms |
1672 KB |
Output is correct |
15 |
Correct |
12 ms |
2444 KB |
Output is correct |