fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn=1e7;
  4. int p[maxn];
  5.  
  6. int main() {
  7. ios::sync_with_stdio(0);
  8. cin.tie(0);
  9.  
  10. long long k;
  11. int n;
  12. cin >> n >> k;
  13. for(int i = 0; i < n; i++)
  14. cin >> p[i];
  15. long long minn = INT64_MAX;
  16. for(int i = 0; i < n; ++i) {
  17. for(int j = i+1; j < n; ++j) {
  18. minn=min(minn,llabs(p[i] * p[j] - k));
  19.  
  20. }
  21. }
  22.  
  23. cout << minn;
  24.  
  25.  
  26.  
  27.  
  28.  
  29. }
Success #stdin #stdout 0.01s 5268KB
stdin
5 4
 1 3 3 2 1
stdout
1