結果

問題 No.2217 Suffix+
ユーザー HIcoder
提出日時 2023-07-13 19:08:23
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 1,109 bytes
コンパイル時間 846 ms
コンパイル使用メモリ 106,876 KB
最終ジャッジ日時 2025-02-15 10:14:44
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<set> 
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<numeric>
#include<queue>
#include<cmath>
#include <unordered_set>
using namespace std;
typedef long long ll;
const ll INF=1LL<<60;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;
const ll MOD=1e9+7;

int main(){
    ll N,K;
    cin>>N>>K;
    vector<ll> A(N+1);
    ll lb=INF;
    for(int i=1;i<=N;i++){
        cin>>A[i];
        lb=min(lb,A[i]);
    }

    ll ub=INF;//lbは必ず達成できる

    while(ub-lb>1){
        ll mid=(ub+lb)/2;//mid以上にできるかどうか

        ll cnt=0;

        ll tot=0;

        for(int i=1;i<=N;i++){
            ll t=max(mid-(tot+A[i]),0LL);
            if(t>0){
                //(t+(i-1))/i回, 足さないといけない
                ll step=(t+(i-1))/i;
                tot+=step*i;//i~Nにたされる数

                cnt+=step;
            }
        }

        //K回以下でmidに達成できない
        if(K<cnt){
            ub=mid;
        }else{
            lb=mid;
        }
    
    }

    cout<<lb<<endl;



}
0