#include <stdio.h>
#include <vector>
#include <algorithm>
int P, N;
std::vector<int> T;
bool compare(int a, int b)
{
if ( a < b )
return true;
else
return false;
}
int main()
{
scanf("%d %d\n", &P, &N);
for ( int i = 0 ; i < N ; i ++)
{
int tmp;
scanf("%d", &tmp);
T.push_back(tmp);
}
sort(T.begin(), T.end());
int i = 0;
int sum = 0;
P -= 1;
while ( P - T[i] >= 0 && T.size() > i )
{
sum += P;
P -= T[i];
i++;
}
printf("%d %d",i, sum);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1204 KB |
Output is correct |
2 |
Correct |
0 ms |
1204 KB |
Output is correct |
3 |
Correct |
0 ms |
1204 KB |
Output is correct |
4 |
Correct |
4 ms |
1336 KB |
Output is correct |
5 |
Correct |
0 ms |
1204 KB |
Output is correct |
6 |
Correct |
4 ms |
1336 KB |
Output is correct |
7 |
Correct |
4 ms |
1592 KB |
Output is correct |
8 |
Correct |
12 ms |
1592 KB |
Output is correct |
9 |
Incorrect |
24 ms |
1976 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |