結果

問題 No.156 キャンディー・ボックス
コンテスト
ユーザー じゃがりこ
提出日時 2018-09-07 20:33:39
言語 C90(gcc12)
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 609 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 109 ms
コンパイル使用メモリ 29,636 KB
実行使用メモリ 7,844 KB
最終ジャッジ日時 2026-03-08 16:18:03
合計ジャッジ時間 1,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:18:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   18 |     scanf("%d%d", &N,&M);
      |     ^~~~~~~~~~~~~~~~~~~~
main.c:20:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   20 |         scanf("%d", &C[i]);
      |         ^~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>

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

int main(){
    int N, M, C[100001],i;
    int count = 0;
    
    scanf("%d%d", &N,&M);
    for (i = 0; i < N; i++) {
    	scanf("%d", &C[i]);
    }
    
    qsort((void *)C, N, sizeof(C[0]), int_sort);
    i = 0;
    while(M > 0){
    	if (C[i] > 0) {
    		M--;
    		C[i]--;
    		if (C[i] == 0) {
    			i++;
    			count++;
    		}
    	}
    	else {
    		i++;
    		count++;
    	}
    }
    printf("%d", count);
    
}
0