結果

問題 No.1046 Fruits Rush
ユーザー kusagame12
提出日時 2023-11-22 18:06:14
言語 Java
(openjdk 23)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 927 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 74,940 KB
実行使用メモリ 41,912 KB
最終ジャッジ日時 2024-09-26 07:35:31
合計ジャッジ時間 4,719 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    
    public static void main(String[] args) throws Exception {
        
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] juices = new int[n];
        for(int i = 0 ; i < n ; i++){
            juices[i] = sc.nextInt();
        }
        
        int ans = 0;
        for(int i = 0 ; i < k ; i++){
            int max = -101;
            int index = -1;
            for(int j = 0 ; j < n ; j++){
                if(juices[j] > max){
                    max = juices[j];
                    index = j;
                }
            }   
            if(max <= 0){
                if(i == 0){
                    ans = max;
                }
                break;
            }
            ans += max;
            juices[index] = -101;
        }
      
        System.out.println(ans);
        
    }
    
}
0