#include <stdio.h>
#include <algorithm>
using namespace std;
int p, n, t[100001], cnt;
long long ans;
void input(void)
{
int i;
scanf("%d %d",&p,&n);
for(i=1 ; i<=n ; i++)
scanf("%d",&t[i]);
sort(t+1,t+n+1);
}
void process(void)
{
int i;
p--;
for(i=1 ; i<=n ; i++)
{
if(p>=t[i])
{
cnt++;
ans+=p;
p-=t[i];
}
else
break;
}
}
void output(void)
{
printf("%d %lld",cnt,ans);
}
int main(void)
{
input();
process();
output();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1476 KB |
Output is correct |
2 |
Correct |
0 ms |
1476 KB |
Output is correct |
3 |
Correct |
0 ms |
1476 KB |
Output is correct |
4 |
Correct |
0 ms |
1476 KB |
Output is correct |
5 |
Correct |
0 ms |
1476 KB |
Output is correct |
6 |
Correct |
4 ms |
1476 KB |
Output is correct |
7 |
Correct |
4 ms |
1476 KB |
Output is correct |
8 |
Correct |
8 ms |
1476 KB |
Output is correct |
9 |
Correct |
24 ms |
1476 KB |
Output is correct |
10 |
Correct |
20 ms |
1476 KB |
Output is correct |
11 |
Correct |
12 ms |
1476 KB |
Output is correct |
12 |
Correct |
8 ms |
1476 KB |
Output is correct |
13 |
Correct |
0 ms |
1476 KB |
Output is correct |
14 |
Correct |
0 ms |
1476 KB |
Output is correct |
15 |
Correct |
12 ms |
1476 KB |
Output is correct |