- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int arr[10005];
- int n,m,mi,d;
- while(cin>>n){
- mi=1000001;
- int x,y;
- for(int i=0;i<n;i++){
- cin>>arr[i];
- }
- cin>>m;
- for(int i=0;i<n-1;i++){
- for(int j=i+1;j<n;j++){
- if((arr[i]+arr[j])==m){
- d=(arr[i]>arr[j]?arr[i]-arr[j]:arr[j]-arr[i]);
- if(d<mi){
- mi=d;
- x=arr[i];
- y=arr[j];
- }
- }
- }
- }
- if(x>y){
- int t;
- t=x;
- x=y;
- y=t;
- }
- cout<<"Peter should buy books whose prices are "<<x<<" and "<<y<<".\n\n";
- }
- return 0;
- }
Sunday, 18 November 2018
uva problem 11057 Exact Sum solution
Subscribe to:
Post Comments (Atom)
variable declaration of c program
#include <stdbool.h> #include<bits/stdc++.h> #include <stdio.h> #include <string.h> #include <std...
-
#include<bits/stdc++.h> #include<cmath> #include<algorithm> #define mx 20000005 using namespace std ; ...
-
#include<stdio.h> #include<string.h> int main ( void ) { char y [ 100001 ] ; int m4,m100,m400,m15...
-
#include<bits/stdc++.h> using namespace std ; int main ( ) { int arr [ 10005 ] ; int n,m,mi,d ; ...
No comments:
Post a Comment