File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change 1+ #include < iostream>
2+ #include < algorithm>
3+ using namespace std ;
4+ int main () {
5+ int nth;
6+ cin>>nth;
7+ while (nth--){
8+ int sum=0 ;
9+ int temp[100 ] = {0 };
10+ bool test=true ;
11+ int a[1000000 ];
12+ int n;
13+ cin>>n;
14+ for (int i=0 ;i<n;i++){
15+ cin>>a[i];
16+ }
17+ int no;
18+ cin>>no;
19+ sort (a,a+n); // Sort this so it will take less time
20+ for (int i=0 ;i<n;i++){
21+ for ( int j=1 +i;j<n;j++){
22+ if (a[i] + a[j] == no){
23+ if (test){
24+ sum = a[j] - a[i];
25+ test = false ;
26+ }
27+ int min = a[j] - a[i];
28+ if (min <= sum){
29+ sum = min;
30+ }
31+ }
32+ }
33+ }
34+ for (int i=0 ;i<n;i++){
35+ for ( int j=1 +i;j<n;j++){
36+ if (a[j] - a[i] == sum && a[i] + a[j] == no){
37+
38+ cout<<" Deepak should buy roses whose prices are " <<a[i]<<" and " <<a[j]<<" ." <<endl;
39+ goto label;
40+ }
41+ // else if(a[j] - a[i] == sum && a[i] + a[j] == no && a[j] >= a[i]){
42+ // cout<<"Deepak should buy roses whose prices are "<<a[j]<<" and "<<a[i]<<"."<<endl;
43+ // }
44+ }
45+ }
46+ label:;
47+ }
48+ }
You can’t perform that action at this time.
0 commit comments