-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11057.cpp
More file actions
executable file
·42 lines (32 loc) · 788 Bytes
/
11057.cpp
File metadata and controls
executable file
·42 lines (32 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// UVA official solution not mine :)
#include <iostream>
#include <algorithm>
using namespace std;
int books[10000];
int main()
{
int N, M;
while (cin >> N)
{
for (int i = 0; i < N; ++i)
cin >> books[i];
sort(books, books + N);
cin >> M;
int i = 0, j = N - 1;
int bI, bJ;
while (i < j)
{
if (books[i] + books[j] < M)
++i;
else if (books[i] + books[j] == M)
{
bI = i;
bJ = j;
++i; --j;
}
else
--j;
}
cout << "Peter should buy books whose prices are " << books[bI] << " and " << books[bJ] << ".\n\n";
}
}