結果

問題 No.5 数字のブロック
ユーザー asdfghjkl;asdfghjkl;
提出日時 2020-03-12 19:14:47
言語 C
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 455 bytes
コンパイル時間 343 ms
コンパイル使用メモリ 29,056 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-19 04:20:05
合計ジャッジ時間 1,571 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other WA * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}

int main(void){
int l,n,w[10005];
scanf("%d",&l);
scanf("%d",&n);

for(int i=0;i<n;i++){
    scanf("%d",&w[i]);
}

qsort(w,n,sizeof(int),cmp);
int sum=0;

for(int i=0;;i++){
    if(l>sum){sum=sum-w[i];break;}
    sum=sum+w[i];
}
printf("%d\n",sum);
}





0