結果

問題 No.409 ダイエット
ユーザー latte0119latte0119
提出日時 2016-08-06 00:11:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 1,626 bytes
コンパイル時間 1,542 ms
コンパイル使用メモリ 148,032 KB
実行使用メモリ 10,832 KB
最終ジャッジ日時 2023-09-08 16:53:37
合計ジャッジ時間 7,444 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,384 KB
testcase_20 AC 1 ms
4,384 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,384 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
testcase_28 AC 2 ms
4,384 KB
testcase_29 AC 2 ms
4,384 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 1 ms
4,380 KB
testcase_32 AC 1 ms
4,380 KB
testcase_33 AC 1 ms
4,380 KB
testcase_34 AC 2 ms
4,380 KB
testcase_35 AC 2 ms
4,380 KB
testcase_36 AC 3 ms
4,384 KB
testcase_37 AC 2 ms
4,384 KB
testcase_38 AC 3 ms
4,384 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 2 ms
4,384 KB
testcase_41 AC 3 ms
4,384 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,384 KB
testcase_44 AC 2 ms
4,384 KB
testcase_45 AC 3 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 2 ms
4,380 KB
testcase_48 AC 2 ms
4,380 KB
testcase_49 AC 2 ms
4,384 KB
testcase_50 AC 2 ms
4,380 KB
testcase_51 AC 2 ms
4,380 KB
testcase_52 AC 2 ms
4,384 KB
testcase_53 AC 3 ms
4,384 KB
testcase_54 AC 3 ms
4,384 KB
testcase_55 AC 47 ms
6,144 KB
testcase_56 AC 52 ms
5,636 KB
testcase_57 AC 94 ms
10,484 KB
testcase_58 AC 41 ms
6,084 KB
testcase_59 AC 56 ms
6,584 KB
testcase_60 AC 36 ms
6,080 KB
testcase_61 AC 84 ms
10,184 KB
testcase_62 AC 89 ms
10,264 KB
testcase_63 AC 82 ms
9,084 KB
testcase_64 AC 43 ms
6,096 KB
testcase_65 AC 83 ms
7,256 KB
testcase_66 AC 93 ms
9,772 KB
testcase_67 AC 71 ms
10,292 KB
testcase_68 AC 56 ms
6,404 KB
testcase_69 AC 81 ms
10,580 KB
testcase_70 AC 106 ms
9,960 KB
testcase_71 AC 58 ms
6,200 KB
testcase_72 AC 127 ms
9,632 KB
testcase_73 AC 115 ms
9,480 KB
testcase_74 AC 74 ms
9,216 KB
testcase_75 AC 118 ms
10,348 KB
testcase_76 AC 86 ms
8,804 KB
testcase_77 AC 55 ms
5,052 KB
testcase_78 AC 65 ms
8,720 KB
testcase_79 AC 52 ms
5,928 KB
testcase_80 AC 120 ms
9,588 KB
testcase_81 AC 115 ms
9,580 KB
testcase_82 AC 87 ms
9,184 KB
testcase_83 AC 93 ms
9,404 KB
testcase_84 AC 74 ms
6,372 KB
testcase_85 AC 9 ms
4,384 KB
testcase_86 AC 74 ms
6,320 KB
testcase_87 AC 105 ms
10,832 KB
testcase_88 AC 42 ms
4,808 KB
testcase_89 AC 82 ms
5,448 KB
testcase_90 AC 38 ms
4,380 KB
testcase_91 AC 87 ms
5,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

typedef long long ll;
struct ConvexHullTrick {
	vector<pair<ll, ll>> ls; // slope, intercept

	bool check(pair<ll, ll> l1, pair<ll, ll> l2, pair<ll, ll> l3) {
		return (l2.first - l1.first) * (l3.second - l2.second) >= (l2.second - l1.second) * (l3.first - l2.first);
	}

	void add(ll a, ll b) {
		pair<ll, ll> l(a, b);
		while (ls.size() >= 2 && check(ls[ls.size() - 2], ls[ls.size() - 1], l)) ls.pop_back();
		ls.emplace_back(l);
	}

	ll f(int k, ll x) {
		return ls[k].first * x + ls[k].second;
	}

	ll query(ll x) {
		int low = -1;
		int high = ls.size() - 1;
		while (high - low > 1) {
			int mid = (low + high) / 2;
			(f(mid, x) <= f(mid + 1, x) ? low : high) = mid;
		}
		return f(high, x);
	}
};

int N,A,B,W;
int D[300000];

signed main(){
    cin>>N>>A>>B>>W;
    rep(i,N)cin>>D[i];

    W-=A*N;
    W+=B*N*(N+1)/2;

    int mi=0;

    ConvexHullTrick cht;
    cht.add(0,0);
    rep(i,N){
        int t=-cht.query(i)+D[i]+A-(N-i)*(i+1)*B;
        chmin(mi,t);
        cht.add((i+1)*B,-t-B*N*(i+1));
    }

    cout<<mi+W<<endl;
    return 0;
}
0