結果

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

ソースコード

diff #

#include <stdio.h>

int main(){
   int val,quantity;
   scanf("%d%d",&val,&quantity);
   
   int fresh[val];
   for(int i = 0;i < val;i ++){
   	scanf("%d",&fresh[i]);
   }
   
   for(int i = 0;i < val;i ++){
		for(int j = 0;j < val;j ++){
			if(fresh[i] > fresh[j]){
				int temp = fresh[i];
				fresh[i] = fresh[j];
				fresh[j] = temp;
			}
		}
    }

	int ans = 0;
	for(int i = 0;i < quantity;i ++){
		//printf("新鮮さ:%d ans:%d",fresh[i]);
		if(fresh[i] > 0){
			ans += fresh[i];
		}
	}
	
	if(ans == 0){
		printf("%d",fresh[0]);
	}else{
		printf("%d",ans);	
	}
}
0