結果
| 問題 | 
                            No.198 キャンディー・ボックス2
                             | 
                    
| コンテスト | |
| ユーザー | 
                             pengin_2000
                         | 
                    
| 提出日時 | 2021-11-19 23:54:20 | 
| 言語 | C  (gcc 13.3.0)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 531 bytes | 
| コンパイル時間 | 249 ms | 
| コンパイル使用メモリ | 25,856 KB | 
| 実行使用メモリ | 6,824 KB | 
| 最終ジャッジ日時 | 2025-01-01 23:47:12 | 
| 合計ジャッジ時間 | 1,615 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 22 WA * 4 | 
コンパイルメッセージ
main.c: In function ‘main’:
main.c:5:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    5 |         scanf("%lld", &b);
      |         ^~~~~~~~~~~~~~~~~
main.c:7:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    7 |         scanf("%d", &n);
      |         ^~~~~~~~~~~~~~~
main.c:11:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   11 |                 scanf("%lld", &c[i]);
      |                 ^~~~~~~~~~~~~~~~~~~~
            
            ソースコード
#include<stdio.h>
int main()
{
	long long int b;
	scanf("%lld", &b);
	int n;
	scanf("%d", &n);
	int i, j;
	long long int c[11];
	for (i = 0; i < n; i++)
		scanf("%lld", &c[i]);
	long long int cnt, bb, ans = 1000000000000000;
	for (i = 0; i < n; i++)
	{
		bb = b;
		cnt = 0;
		for (j = 0; j < n; j++)
		{
			if (c[i] < c[j])
			{
				cnt += c[j] - c[i];
				bb += c[j] - c[i];
			}
			else
			{
				cnt += c[i] - c[j];
				bb -= c[i] - c[j];
			}
		}
		if (bb >= 0 && ans > cnt)
			ans = cnt;
	}
	printf("%lld\n", ans);
	return 0;
}
            
            
            
        
            
pengin_2000