#include<bits/stdc++.h>#defineendl'\n'usingnamespace std;typedeflonglong LL;constint N =1e5+10;int n, k;int a[N];boolcheck(int mid){int rec =1e9, cnt =1;for(int i =0; i < n; i ++){int j = i;while(j < n && a[j]- a[i]< mid) j ++;if(j < n) rec =min(rec, a[j]- a[i]), cnt ++;i = j -1;}return cnt >= k && rec >= mid;}voidsolve(){cin >> n >> k;for(int i =0; i < n; i ++) cin >> a[i];int l =1, r =1e6+10;while(l < r){int mid = l + r +1>>1;if(check(mid)) l = mid;else r = mid -1;}cout << r << endl;}intmain(){cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);int T =1;// cin >> T;while(T --){solve();}return0;}
T2(01BFS)
#include<bits/stdc++.h>#definexfirst#defineysecond#defineendl'\n'usingnamespace std;typedeflonglong LL;typedef pair<int,int> PII;constint N =1e5+10;int n, m;int dx[4]={-1,0,1,0};int dy[4]={0,1,0,-1};voidsolve(){cin >> n >> m;vector<vector<int>>g(n,vector<int>(m));vector<vector<int>>dist(n,vector<int>(m,1e9));for(int i =0; i < n; i ++){for(int j =0; j < m; j ++){cin >> g[i][j];}}deque<PII> q;q.push_back({0,0});dist[0][0]= g[0][0];while(q.size()){auto t = q.front(); q.pop_front();int x = t.x, y = t.y;for(int i =0; i <4; i ++){int a = x + dx[i], b = y + dy[i];if(a >=0&& a < n && b >=0&& b < m){if(dist[a][b]> dist[x][y]+ g[a][b]){dist[a][b]= dist[x][y]+ g[a][b];if(g[a][b]==1){q.push_back({a, b});}else{q.push_front({a, b});}}}}}cout << dist[n -1][m -1]<< endl;}intmain(){cin.tie(0); cout.tie(0);std::ios::sync_with_stdio(false);int T =1;// cin >> T;while(T --){solve();}return0;}