fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e6 + 5;
  6. int a[N];
  7.  
  8. int main() {
  9. freopen("MUASAM.INP","r",stdin);
  10. freopen("MUASAM.OUT","w",stdout);
  11. ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  12.  
  13. int n,l,r; cin >> n >> l >> r;
  14. multiset<int> s;
  15. for (int i = 1; i <= n; i++) cin >> a[i];
  16.  
  17. s.insert(a[1]);
  18. int ans = INT_MAX;
  19. for (int i = 2; i <= n; i++) {
  20. if (s.lower_bound(l-a[i]) != s.end()) {
  21. int target = *s.lower_bound(l-a[i]);
  22. if (target <= r - a[i]) {
  23. ans = min(ans, a[i] + target);
  24. }
  25. }
  26. s.insert(a[i]);
  27. }
  28. cout << ans;
  29. return 0;
  30. }
  31.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty