fork download
  1. #include <bits/stdc++.h>
  2. #define fi first
  3. #define se second
  4. #define pb push_back
  5. using namespace std;
  6. typedef long long ll;
  7. typedef double dbl;
  8. typedef pair<int,int> pii;
  9.  
  10. const int maxn = 1e5+5;
  11. int X,N,b;
  12. set<int> A;
  13. multiset<int> ans;
  14.  
  15. int main(){
  16. cin >> X >> N;
  17. A.insert(0);
  18. A.insert(X);
  19. ans.insert(X);
  20. while(N--){
  21. cin >> b;
  22. auto nt = A.upper_bound(b);
  23. auto pv = nt;
  24. pv--;
  25. ans.erase(ans.find(*nt-*pv));
  26. ans.insert(b-*pv);
  27. ans.insert(*nt-b);
  28. A.insert(b);
  29. cout << *ans.rbegin() << " ";
  30. }
  31. }
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty