結果

問題 No.1046 Fruits Rush
ユーザー ytflhjo
提出日時 2020-05-10 10:58:32
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 568 bytes
コンパイル時間 1,587 ms
コンパイル使用メモリ 172,464 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-07 06:48:48
合計ジャッジ時間 2,196 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll GCD(ll x,ll y){
    if(y == 0) return x;
    else return GCD(y,x%y);
}
const int MOD = 1000000007;

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> vec;
    for(int i = 0; i < n;i++){
        int b;
        cin >> b;
        vec.push_back(b);
    }
    int ans = 0;
    sort(vec.begin(),vec.end(),greater<int>());
    for(int i = 0;i < k;i++){
        if(vec[i] > 0){
            ans+=vec[i];
        }
    }
    if(ans == 0){
        ans+=vec[0];
    }
    cout << ans << endl;
}



0