#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int P,N;
vector<int> data;
void input()
{
scanf("%d%d",&P,&N);
data.resize(N);
for(int i=0;i<N;i++)
{
scanf("%d",&data[i]);
}
sort(data.begin(),data.end());
}
void process()
{
P--;
long long int ans=0;
int i;
for(i=0;i<N;i++)
{
if(P-data[i]>=0)
{
ans+=P;
}
else break;
P-=data[i];
}
printf("%d %lld\n",i,ans);
}
int main()
{
input();
process();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
1236 KB |
Output is correct |
2 |
Correct |
0 ms |
1236 KB |
Output is correct |
3 |
Correct |
0 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1236 KB |
Output is correct |
5 |
Correct |
0 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
8 ms |
1408 KB |
Output is correct |
8 |
Correct |
8 ms |
1428 KB |
Output is correct |
9 |
Correct |
24 ms |
1624 KB |
Output is correct |
10 |
Correct |
24 ms |
1604 KB |
Output is correct |
11 |
Correct |
16 ms |
1624 KB |
Output is correct |
12 |
Correct |
12 ms |
1604 KB |
Output is correct |
13 |
Correct |
0 ms |
1236 KB |
Output is correct |
14 |
Correct |
0 ms |
1236 KB |
Output is correct |
15 |
Correct |
12 ms |
1616 KB |
Output is correct |