結果
| 問題 |
No.2217 Suffix+
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-07-13 19:10:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 178 ms / 2,000 ms |
| コード長 | 1,231 bytes |
| コンパイル時間 | 827 ms |
| コンパイル使用メモリ | 106,776 KB |
| 最終ジャッジ日時 | 2025-02-15 10:14:50 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 33 |
ソースコード
/*
AC
iに干渉できるのは j=0~iのみ
最大値の最小値とかは決め打ちが便利
AGC009Dに似てる
*/
#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;
}