結果

問題 No.31 悪のミックスジュース
ユーザー fumiphysfumiphys
提出日時 2020-04-09 23:52:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,842 bytes
コンパイル時間 2,063 ms
コンパイル使用メモリ 176,900 KB
実行使用メモリ 162,684 KB
最終ジャッジ日時 2024-09-14 02:16:32
合計ジャッジ時間 3,361 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// includes
#include <bits/stdc++.h>
using namespace std;

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;

const int b = 200000;
ll dp[110][b+10];

int main(int argc, char const* argv[])
{
  int n; cin >> n;
  ll V; cin >> V;
  vector<ll> c(n); cin >> c;
  vector<ll> acc = c;
  FOR(i, 1, n){
    acc[i] += acc[i-1];
  }
  ll res = acc.back();
  V -= n;
  vector<int> e(n); rep(i, n)e[i] = i;
  sort(whole(e), [&](int i, int j){
    // acc[i] / (i + 1) < acc[j] / (j + 1)
    return acc[i] * (j + 1) < acc[j] * (i + 1);
  });
  if(V > b){
    ll rem = (V - b + e[0]) / (e[0] + 1);
    V -= rem * (e[0] + 1);
    res += acc[e[0]] * (e[0] + 1) * rem;
  }
  rep(i, n + 1){
    rep(j, b + 1)dp[i][j] = linf;
  }
  dp[0][0] = 0;
  rep(i, n){
    rep(j, b + 1){
      dp[i+1][j] = dp[i][j];
      if(j>=i+1)chmin(dp[i+1][j], dp[i+1][j-(i+1)] + acc[i]);
    }
  }
  for(int i = b - 1; i >= 0; i--)chmin(dp[n][i], dp[n][i+1]);
  if(V > 0){
    res += dp[n][V];
  }
  cout << res << endl;
  return 0;
}
0