結果

問題 No.1046 Fruits Rush
ユーザー sasa
提出日時 2025-03-17 17:15:07
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 511 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 28,288 KB
実行使用メモリ 7,324 KB
最終ジャッジ日時 2025-03-17 17:15:09
合計ジャッジ時間 1,441 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:4:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    4 |         scanf("%d%d",&element,&num);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
main.cpp:8:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |                 scanf("%d",&fresh[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~~

ソースコード

diff #

#include <stdio.h>
int main(void){
	int element,num;
	scanf("%d%d",&element,&num);
	
	int fresh[element];
	for(int i = 0;i < element;i ++){
		scanf("%d",&fresh[i]);
	}
	
	// ソート
	for(int i = 0;i < element;i ++){
		for(int j = 0;j < element;j ++){
			if(fresh[i] > fresh[j]){
				int tmp = fresh[i];
				fresh[i] = fresh[j];
				fresh[j] = tmp;
			}
		}
	}
	
	int ans = 0;
	for(int i = 0;i < num;i ++){
		if(fresh[i] > 0){
			ans += fresh[i];
		}
	}
	if(ans == 0){
		ans = fresh[0];
	}
	printf("%d",ans);
}
0