結果
| 問題 |
No.1046 Fruits Rush
|
| コンテスト | |
| ユーザー |
toto
|
| 提出日時 | 2025-04-01 14:46:36 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 813 bytes |
| コンパイル時間 | 497 ms |
| コンパイル使用メモリ | 28,288 KB |
| 実行使用メモリ | 7,716 KB |
| 最終ジャッジ日時 | 2025-04-01 14:46:38 |
| 合計ジャッジ時間 | 1,434 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:6:9: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
6 | scanf("%d%d",&val,&quantity);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
main.cpp:11:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
11 | scanf("%d",&fresh[i]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#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 ++){
if(fresh[i] > 0){
ans += fresh[i];
}
}
// 入れる果実がなければ初めの果実を1つだけ入れる
if(ans == 0){
printf("%d",fresh[0]);
}else{
printf("%d",ans);
}
}
toto