結果
| 問題 |
No.1046 Fruits Rush
|
| コンテスト | |
| ユーザー |
Maeda
|
| 提出日時 | 2025-03-11 11:48:58 |
| 言語 | C (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 1 ms / 2,000 ms |
| コード長 | 474 bytes |
| コンパイル時間 | 340 ms |
| コンパイル使用メモリ | 25,472 KB |
| 実行使用メモリ | 7,324 KB |
| 最終ジャッジ日時 | 2025-03-11 11:48:59 |
| 合計ジャッジ時間 | 1,345 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
コンパイルメッセージ
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("%d %d",&n,&k);
| ^~~~~~~~~~~~~~~~~~~~
main.c:8:17: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
8 | scanf("%d",&fresh[i]);
| ^~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
int main(void){
int n = 0 , k = 0;
scanf("%d %d",&n,&k);
int fresh[n];
for(int i = 0 ; i < n ; i ++){
scanf("%d",&fresh[i]);
}
for(int i = 0 ; i < n ; i++){
for(int j = i ; j < n ; j++ ){
if(fresh[i] < fresh[j]){
int num = fresh[i];
fresh[i] = fresh[j];
fresh[j] = num;
}
}
}
int delicious = fresh[0];
for(int i = 1 ; i < k ; i++){
if(fresh[i] <= 0){
break;
}
delicious += fresh[i];
}
printf("%d",delicious);
}
Maeda