#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
int p=0;
int n=0;
int *farr;
//int arr[100000]={0,};
int sum=0;
int tmp=0;
int i=0;
int count=0;
scanf("%d",&p);
scanf("%d",&n);
farr=(int*)malloc(n*sizeof(int));
if(farr==NULL)
{
exit(0);
}
for(i=0;i<n;i++){
scanf("%d",&farr[i]);
}
sort(farr,farr+n);
for(int i=0; i<n;i++){
if(i!=n-1){
tmp=tmp+farr[i];
if(tmp>p)
break;
}
count++;
}
tmp = p-tmp-1;
for(i=n-2;i>=0;i--){
sum = sum+(tmp+farr[i]);
tmp = tmp+farr[i];
}
printf("%d ",count);
printf("%d",sum);
free(farr);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
1088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |