fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const long long MaxN = 1e5 + 5;
  4. long long n,k;
  5. long long a[MaxN];
  6. int main()
  7. {
  8. ios_base::sync_with_stdio(0);
  9. cin.tie(0);
  10. if(fopen("ANTS.inp","r"))
  11. {
  12. freopen("ANTS.inp","r",stdin);
  13. freopen("ANTS.out","w",stdout);
  14. }
  15. cin >> n >> k;
  16. for (long long i=1; i<=n; i++)
  17. {
  18. cin >> a[i];
  19. }
  20. long long ans = 0;
  21. for (long long i=1; i<=n; i++)
  22. {
  23. if(a[i]<0)
  24. {
  25. ans=max(ans,abs(a[i]));
  26. }
  27. else
  28. {
  29. ans=max(ans,k-a[i]);
  30. }
  31. }
  32. cout << ans;
  33. }
  34.  
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout
Standard output is empty