fork download
  1. #include <iostream>
  2. #include <set>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. int x,n;
  8. cin>>x>>n;
  9.  
  10. int a[n];
  11. for(int i=0;i<n;i++)
  12. {
  13. cin>>a[i];
  14. }
  15.  
  16. set<int> pos;
  17. multiset<int> length;
  18. pos.insert(0);
  19. pos.insert(x);
  20. length.insert(x);
  21.  
  22. for(int i=0;i<n;i++)
  23. {
  24. pos.insert(a[i]);
  25. auto it = pos.find(a[i]);
  26. int nextValue = *next(it);
  27. int prevValue = *prev(it);
  28. length.erase(length.find(nextValue-prevValue));
  29. length.insert(nextValue - a[i]);
  30. length.insert(a[i] - prevValue);
  31.  
  32. cout<<*length.rbegin()<<" ";
  33.  
  34. }
  35.  
  36. return 0;
  37. }
Success #stdin #stdout 0.01s 5288KB
stdin
8 3
3 6 2
stdout
5 3 3