이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("avx,avx2,fma,lzcnt,popcnt")
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pb push_back
#define pf push_front
#define ii pair<int,int>
#define ill pair<ll,ll>
#define el cout<<'\n'
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define int long long
const ll mod=1e9+7;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
const int nmax=1e5;
void add ( int&a , int b ) { if ((a+=b) > mod ) a -= mod ; }
void sub ( int&a , int b ) { if ((a-=b) < 0 ) a += mod ; }
template<typename T> void chkmin(T& x, T y) {if(x > y) x = y;}
template<typename T> void chkmax(T& x, T y) {if(x < y) x = y;}
using namespace std;
int a[nmax+5];
int ans=1e9;
bool check(int dis,int k,int n)
{
int cnt=0;
int l=1;
int res=0;
while(l<=n)
{
cnt++;
int tmp=a[l]+dis-1;
int cur=a[l];
while(tmp>=a[l]&&l<=n)
l++;
res+=a[l-1]-cur+1;
}
// cout<<dis<<" "<<cnt;el;
if(cnt<=k)
ans=min(ans,res);
return (cnt<=k);
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
int l=1,r=1e9;
int res=-1;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid,k,n))
{
res=mid;
r=mid-1;
}
else
l=mid+1;
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
stove.cpp: In function 'int main()':
stove.cpp:57:8: warning: variable 'res' set but not used [-Wunused-but-set-variable]
57 | int res=-1;
| ^~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |