結果

問題 No.1046 Fruits Rush
ユーザー sasa
提出日時 2025-03-17 17:14:10
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 475 bytes
コンパイル時間 412 ms
コンパイル使用メモリ 28,288 KB
実行使用メモリ 7,328 KB
最終ジャッジ日時 2025-03-17 17:14:12
合計ジャッジ時間 1,503 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 11 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
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];
		}
	}
	printf("%d",ans);
}
0