結果

問題 No.2217 Suffix+
ユーザー no wayno way
提出日時 2023-02-18 12:09:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 106 ms / 2,000 ms
コード長 546 bytes
コンパイル時間 1,506 ms
コンパイル使用メモリ 166,296 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 23:26:42
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const long long INF=2e14;
long long a[N];
int n,k;
long long ans;
int check(long long x){
	long long t=0,sum=0;
	for (int i=1;i<=n;i++) if (a[i]+t<x){
		sum+=(x-a[i]-t-1)/i+1;
		t+=1ll*i*((x-a[i]-t-1)/i+1);
	}
	return sum<=k;
}
void s(long long l,long long r){
	if (l>r) return;
	long long mid=(l+r)/2;
	if (check(mid)) ans=mid,s(mid+1,r); else s(l,mid-1);
}
int main(){
	scanf("%d%d",&n,&k);
	for (int i=1;i<=n;i++) scanf("%lld",&a[i]);
	ans=0;
	s(0,INF);
	printf("%lld\n",ans);
}
0