結果

問題 No.5 数字のブロック
コンテスト
ユーザー bonyuta0204
提出日時 2017-04-13 17:27:42
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 809 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 214 ms
コンパイル使用メモリ 39,268 KB
最終ジャッジ日時 2026-02-21 23:40:31
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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


int comp( const void *c1, const void *c2 );

int main(void){

    int l, n;
    scanf("%d %d",&l, &n);
    int blocks[n] ;
    int i;
    for (i=0;i<n;i++){
        scanf("%d", &blocks[i]) ;
    }
    // sort blocks
    qsort(blocks, n, sizeof(int), comp);

    for(i=0;i<n;i++){
      //  printf("%d", blocks[i]) ;
    }
    // check if blocks can be accomdated in bocks(L)
    int total = 0;
    int answer;
    for(i=0;i<n;i++){
        total += blocks[i];
        if(total > l){
            break; 
        }
        answer = i + 1;
    }
    printf("%d\n", answer);

}

int comp( const void *c1, const void *c2 )
{
  int tmp1 = *(int *)c1;
  int tmp2 = *(int *)c2;

  if( tmp1 < tmp2 )  return -1;
  if( tmp1 == tmp2 ) return  0;
  if( tmp1 > tmp2 )  return  1;
}
0