#include <cstdio>
#include <algorithm>
using namespace std;
int p,n;
int data[100010];
int main()
{
scanf("%d%d",&p,&n);
int i;
for(i=0;i<n;++i) scanf("%d",data+i);
sort(data,data+n);
int cs=0;
for(i=0;i<n;++i){
if(data[i]+cs>=p) break;
else cs+=data[i];
}
printf("%d ",i);
int j;
typedef long long ll;
ll ans=0, tmp=p-1-cs;
for(j=i-1;j>=0;--j){
tmp+=data[j];
ans+=tmp;
}
printf("%lld\n",ans);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1472 KB |
Output is correct |
2 |
Correct |
0 ms |
1472 KB |
Output is correct |
3 |
Correct |
0 ms |
1472 KB |
Output is correct |
4 |
Correct |
0 ms |
1472 KB |
Output is correct |
5 |
Correct |
0 ms |
1472 KB |
Output is correct |
6 |
Correct |
4 ms |
1472 KB |
Output is correct |
7 |
Correct |
8 ms |
1472 KB |
Output is correct |
8 |
Correct |
13 ms |
1472 KB |
Output is correct |
9 |
Correct |
18 ms |
1472 KB |
Output is correct |
10 |
Correct |
25 ms |
1472 KB |
Output is correct |
11 |
Correct |
18 ms |
1472 KB |
Output is correct |
12 |
Correct |
7 ms |
1472 KB |
Output is correct |
13 |
Correct |
0 ms |
1472 KB |
Output is correct |
14 |
Correct |
0 ms |
1472 KB |
Output is correct |
15 |
Correct |
9 ms |
1472 KB |
Output is correct |