Created
February 21, 2014 03:19
-
-
Save euyuil/9128145 to your computer and use it in GitHub Desktop.
Codeforces 395A: Skis. 2-Sum problem. 1 solution for both 395A1 and 395A2. (http://codeforces.com/problemset/problem/395/A1, http://codeforces.com/problemset/problem/395/A2)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 395A1 & 395A2 - Skis | |
// http://codeforces.com/problemset/problem/395/A1 | |
// http://codeforces.com/problemset/problem/395/A2 | |
#include <cstdlib> | |
#include <iostream> | |
#include <algorithm> | |
const int N = 1111111; | |
int n, q, arr[N]; | |
using namespace std; | |
int main() | |
{ | |
cin >> n >> q; | |
for (int i = 0; i < n; ++i) | |
cin >> arr[i]; | |
sort(arr, arr + n); | |
int ans = 0; | |
{ | |
int i = 0, j = n - 1; | |
while (i < j) | |
{ | |
if (arr[i] + arr[j] > q) | |
--j; | |
else if (arr[i] + arr[j] < q) | |
++i; | |
else | |
--j, ++i, ++ans; | |
} | |
} | |
cout << ans << endl; | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment