//Problem K
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
long long a[100000];
long long start,E;
int main() {
long long i,j,k,n,tmp;
scanf("%lld",&tmp);
scanf("%lld",&n);
tmp--;
for ( i=0; i<n; i++ ) scanf("%lld",&a[i]);
sort(a,a+n);
long long res=0,cnt=0;
for ( i=0; i<n; i++ ) {
if ( tmp<=a[i] ) break;
res+=tmp;
cnt++;
tmp-=a[i];
}
printf("%lld %lld\n",cnt,res);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2452 KB |
Output is correct |
2 |
Correct |
0 ms |
2452 KB |
Output is correct |
3 |
Correct |
0 ms |
2452 KB |
Output is correct |
4 |
Correct |
4 ms |
2452 KB |
Output is correct |
5 |
Correct |
0 ms |
2452 KB |
Output is correct |
6 |
Correct |
4 ms |
2452 KB |
Output is correct |
7 |
Correct |
8 ms |
2452 KB |
Output is correct |
8 |
Correct |
4 ms |
2452 KB |
Output is correct |
9 |
Correct |
24 ms |
2452 KB |
Output is correct |
10 |
Correct |
20 ms |
2452 KB |
Output is correct |
11 |
Correct |
16 ms |
2452 KB |
Output is correct |
12 |
Correct |
12 ms |
2452 KB |
Output is correct |
13 |
Correct |
0 ms |
2452 KB |
Output is correct |
14 |
Correct |
0 ms |
2452 KB |
Output is correct |
15 |
Correct |
12 ms |
2452 KB |
Output is correct |