結果
| 問題 |
No.156 キャンディー・ボックス
|
| コンテスト | |
| ユーザー |
カルロス
|
| 提出日時 | 2015-09-07 16:39:51 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 812 bytes |
| コンパイル時間 | 272 ms |
| コンパイル使用メモリ | 21,632 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-05 15:42:34 |
| 合計ジャッジ時間 | 1,098 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:25:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | scanf("%d %d", &N, &M);
| ^~~~~~~~~~~~~~~~~~~~~~
main.c:27:23: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
27 | for (i=0;i<N;i++) scanf("%d", &c[i]);
| ^~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
void Quicksort(int data[], int left, int right){
int l = left, r = right;
int pivot = data[(left + right) / 2];
int temp;
while(1){
while (data[l] < pivot) l++;
while (pivot < data[r]) r--;
if(r < l) break;
temp = data[l];
data[l] = data[r];
data[r] = temp;
l++, r--;
}
if(left < r) Quicksort(data, left, r);
if(l < right) Quicksort(data, l, right);
}
int main(void){
int i, N, M, ans = 0;
scanf("%d %d", &N, &M);
int c[N];
for (i=0;i<N;i++) scanf("%d", &c[i]);
Quicksort(c, 0, N-1);
i = 0;
while(M>0 && i<N){
if(c[i]>M){
M = 0;
}else{
M -= c[i];
ans++;
}
i++;
}
printf("%d\n", ans);
return 0;
}
カルロス