fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define name "DIFF"
  5. const int MAXN = 2e5+5;
  6. int n, a[MAXN];
  7. int GTNN = MAXN;
  8.  
  9. void setIO(){
  10. ios_base::sync_with_stdio(0);
  11. cin.tie(0); cout.tie(0);
  12. if (fopen(name".inp", "r")){
  13. freopen(name".inp", "r", stdin);
  14. freopen(name".out", "w", stdout);
  15. }
  16. }
  17.  
  18. void inp(){
  19. cin >> n;
  20. for (int i = 1; i<=n; i++) cin >> a[i];
  21. }
  22.  
  23. int main(){
  24. setIO(); // Nhập xuất file
  25. inp();
  26. sort(a+1, a+n+1, greater<int>());
  27. for (int i = 1; i<n; i++){
  28. if (a[i] - a[i+1] < GTNN)
  29. GTNN = a[i] - a[i+1];
  30. }
  31. cout << GTNN;
  32. }
Success #stdin #stdout 0s 5312KB
stdin
5
21 8 3 10 100
stdout
2