#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int A[202020]; multiset L[202020],R[202020]; int getML(int a) { return *L[a].rbegin(); } int getMR(int a) { if(L[a].size()==R[a].size()) return *R[a].begin(); return *L[a].rbegin(); } void add(int t,int a) { L[t].insert(a); int x=*L[t].rbegin(); L[t].erase(L[t].find(x)); R[t].insert(x); if(R[t].size()>L[t].size()) { x=*R[t].begin(); L[t].insert(x); R[t].erase(R[t].find(x)); } } void solve() { int i,j,k,l,r,x,y; cin>>N; FOR(i,N) cin>>A[i]; sort(A,A+N); vector s; FOR(i,N) { add(i,A[i]-i); s.push_back(i); while(s.size()>=2) { x=s.back(); s.pop_back(); y=s.back(); s.pop_back(); if(getML(y)<=getMR(x)) { s.push_back(y); s.push_back(x); break; } if(L[x].size()