Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, x;
- while(scanf("%d", &n)!=EOF)
- {
- vector<int> v;
- for(int i=0 ; i<n ; i++)
- {
- cin >> x;
- v.push_back(x);
- }
- int total;
- cin >> total;
- sort(v.begin(),v.end());
- int mid = n/2;
- int i=0;
- int j=1;
- while(v[mid]+v[i]!=total)
- {
- i++;
- if(i==n)
- {
- i=0;
- mid += j;
- }
- if(j+mid==n)
- {
- mid=0;
- }
- }
- if(v[i] <= v[mid])
- printf("Peter should buy books whose prices are %d and %d.\n", v[i], v[mid]);
- else
- printf("Peter should buy books whose prices are %d and %d.\n", v[mid], v[i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement