結果

問題 No.31 悪のミックスジュース
ユーザー cormorancormoran
提出日時 2016-02-16 23:16:28
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,551 bytes
コンパイル時間 624 ms
コンパイル使用メモリ 75,336 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-22 06:04:07
合計ジャッジ時間 1,454 ms
ジャッジサーバーID
(参考情報)
judge14 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 1 ms
4,348 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<numeric>
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ i=0;i<(int__)(j);i++)
#define repeat(i,j,k) for(int__ i=(j);i<(int__)(k);i++)
#define all(v) v.begin(),v.end()

template<typename T>
ostream& operator << (ostream &os , const vector<T> &v){
    rep(i,v.size()) os << v[i] << (i!=v.size()-1 ? " " : "\n"); return os;
}

template<typename T>
istream& operator >> (istream &is , vector<T> &v){
    rep(i,v.size()) is >> v[i]; return is;
}

#ifdef DEBUG
void debug(){ cerr << endl; }
#endif
template<class F,class...R>
void debug(const F &car,const R&... cdr){
#ifdef DEBUG
    cerr << car << " "; debug(cdr...);
#endif
}


bool solve(){
    int n, v; cin >> n >> v;
    vector<int> C(n); cin >> C;

    if( n >= v ){
        cout << accumulate(all(C), 0) << endl;
        return 0;
    }
    
    auto mini = min_element(all(C));
    ll ans = 0;
    ans += accumulate(mini+1,C.end(), 0);
    v -= C.end() - mini - 1;

    while(v > 0){
        ll num = mini - C.begin() + 1;
        ll c = v / num;
        v -= c * num;        
        ans += accumulate(C.begin(), mini+1, 0)*c;
        mini = min_element(C.begin(), mini);
    }
    cout << ans << endl;
    
    
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}
0