Precreation contest files
This commit is contained in:
35
misc/hsg-hn-2025/muasam.cpp
Normal file
35
misc/hsg-hn-2025/muasam.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int MAX_N = 1e6;
|
||||
int a[MAX_N];
|
||||
|
||||
int main() {
|
||||
freopen("muasam.inp", "r", stdin);
|
||||
freopen("muasam.out", "w", stdout);
|
||||
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n, l, r;
|
||||
cin >> n >> l >> r;
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> a[i];
|
||||
int res = 1e9;
|
||||
|
||||
sort(a, a + n);
|
||||
int L = 0, R = n - 1;
|
||||
while (L < R) {
|
||||
int sum = a[L] + a[R];
|
||||
if (sum > r)
|
||||
R--;
|
||||
else if (sum < l)
|
||||
L++;
|
||||
else {
|
||||
res = min(res, sum);
|
||||
R--;
|
||||
}
|
||||
}
|
||||
cout << res << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user