`{"id":"959c004b-37f3-4fbd-80f7-78eba5d3d8fc","name":"Broken Economy","description":"In a country of novice government, the economic system is changed where only coins are used that too of various denominations. Whenever a foreigner visits this country, they visit a money exchanger to get the currency of the same country. As the foreigner is unaware of the denomination of the country, the money exchange prefers to tell them the denomination which is the nearest maximum and nearest minimum to the denomination mentioned by the foreigner. In case they get the correct guess of the denomination, they are told the same denomination. The denominations are always quoted in ascending order.\r\n\r\nExample 1: In a country, 8 given denominations are as follows\r\n[5, 10, 15, 22, 33, 40, 42, 55]\r\n\r\nThe foreigner asks for denomination 25.\r\nThe money exchange tells them that denominations of 33 and 22 are available.\r\n\r\nExample 2: \r\nIn a country, 5 given denominations are as follows\r\n[7, 14, 18, 25, 30]\r\n\r\nThe foreigner asks for the denomination of 18.\r\n\r\nThe money exchange tells them a denomination of 18 is available. \r\n\r\nYou are required to print the values told by the money exchange to the foreigner.\r\n\r\n1. You are given a number n, representing the size of array a.\r\n2. You are given n numbers, representing elements of the array a.\r\n3. You are given another number d.\r\n4. You are required to find the ceil and floor of d in array a. ","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements\r\nA number d","outputFormat":"A number representing ceil\r\nA number representing floor","constraints":"1 &lt;= n &lt;= 1000\r\n-10^9 &lt;= n1, n2, .. n elements &lt;= 10^9\r\n-10^9 &lt;= d &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\n int* arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n cin>>arr[i];\r\n }\r\n int data;\r\n cin>>data;\r\n \r\n // write your code here\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"n= int(input())\n\nlists= []\n\nfor i in range(0, n):\n ele= int(input())\n lists.append(ele)\n \nkey= int(input())\n\n# Write your code here"}},"points":10,"difficulty":"easy","sampleInput":"10\r\n1\r\n5\r\n10\r\n15\r\n22\r\n33\r\n40\r\n42\r\n55\r\n66\r\n34","sampleOutput":"40\r\n33","questionVideo":"https://www.youtube.com/embed/kQx7nvN_8e4","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"b4e8cfab-ba55-47ad-9b3b-fba2862e03a8","name":"Broken Economy","slug":"broken-economy","type":1}],"next":{"id":"2f403e8a-be97-46b7-87e4-4e4fb487fdb0","name":"First And Last Index","type":3,"slug":"first-and-last-index"},"prev":{"id":"8caea8d5-9ac9-46fc-b846-6a763c8dc1f2","name":"Broken Economy","type":3,"slug":"broken-economy"}}}`

# Broken Economy

In a country of novice government, the economic system is changed where only coins are used that too of various denominations. Whenever a foreigner visits this country, they visit a money exchanger to get the currency of the same country. As the foreigner is unaware of the denomination of the country, the money exchange prefers to tell them the denomination which is the nearest maximum and nearest minimum to the denomination mentioned by the foreigner. In case they get the correct guess of the denomination, they are told the same denomination. The denominations are always quoted in ascending order. Example 1: In a country, 8 given denominations are as follows [5, 10, 15, 22, 33, 40, 42, 55] The foreigner asks for denomination 25. The money exchange tells them that denominations of 33 and 22 are available. Example 2: In a country, 5 given denominations are as follows [7, 14, 18, 25, 30] The foreigner asks for the denomination of 18. The money exchange tells them a denomination of 18 is available. You are required to print the values told by the money exchange to the foreigner. 1. You are given a number n, representing the size of array a. 2. You are given n numbers, representing elements of the array a. 3. You are given another number d. 4. You are required to find the ceil and floor of d in array a.

`{"id":"959c004b-37f3-4fbd-80f7-78eba5d3d8fc","name":"Broken Economy","description":"In a country of novice government, the economic system is changed where only coins are used that too of various denominations. Whenever a foreigner visits this country, they visit a money exchanger to get the currency of the same country. As the foreigner is unaware of the denomination of the country, the money exchange prefers to tell them the denomination which is the nearest maximum and nearest minimum to the denomination mentioned by the foreigner. In case they get the correct guess of the denomination, they are told the same denomination. The denominations are always quoted in ascending order.\r\n\r\nExample 1: In a country, 8 given denominations are as follows\r\n[5, 10, 15, 22, 33, 40, 42, 55]\r\n\r\nThe foreigner asks for denomination 25.\r\nThe money exchange tells them that denominations of 33 and 22 are available.\r\n\r\nExample 2: \r\nIn a country, 5 given denominations are as follows\r\n[7, 14, 18, 25, 30]\r\n\r\nThe foreigner asks for the denomination of 18.\r\n\r\nThe money exchange tells them a denomination of 18 is available. \r\n\r\nYou are required to print the values told by the money exchange to the foreigner.\r\n\r\n1. You are given a number n, representing the size of array a.\r\n2. You are given n numbers, representing elements of the array a.\r\n3. You are given another number d.\r\n4. You are required to find the ceil and floor of d in array a. ","inputFormat":"A number n\r\nn1\r\nn2\r\n.. n number of elements\r\nA number d","outputFormat":"A number representing ceil\r\nA number representing floor","constraints":"1 &lt;= n &lt;= 1000\r\n-10^9 &lt;= n1, n2, .. n elements &lt;= 10^9\r\n-10^9 &lt;= d &lt;= 10^9","sampleCode":{"cpp":{"code":"#include<iostream>\r\nusing namespace std;\r\n\r\nint main(){\r\n int n;\r\n cin>>n;\r\n int* arr = new int[n];\r\n for(int i = 0 ; i < n; i++){\r\n cin>>arr[i];\r\n }\r\n int data;\r\n cin>>data;\r\n \r\n // write your code here\r\n \r\n}"},"java":{"code":"import java.io.*;\r\nimport java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) throws Exception {\r\n // write your code here\r\n }\r\n\r\n}"},"python":{"code":"n= int(input())\n\nlists= []\n\nfor i in range(0, n):\n ele= int(input())\n lists.append(ele)\n \nkey= int(input())\n\n# Write your code here"}},"points":10,"difficulty":"easy","sampleInput":"10\r\n1\r\n5\r\n10\r\n15\r\n22\r\n33\r\n40\r\n42\r\n55\r\n66\r\n34","sampleOutput":"40\r\n33","questionVideo":"https://www.youtube.com/embed/kQx7nvN_8e4","hints":[],"associated":[],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"f10b54f1-0f44-408f-82d5-89c189f4ad57","name":"Function and Arrays","slug":"function-and-arrays","type":0},{"id":"b4e8cfab-ba55-47ad-9b3b-fba2862e03a8","name":"Broken Economy","slug":"broken-economy","type":1}],"next":{"id":"2f403e8a-be97-46b7-87e4-4e4fb487fdb0","name":"First And Last Index","type":3,"slug":"first-and-last-index"},"prev":{"id":"8caea8d5-9ac9-46fc-b846-6a763c8dc1f2","name":"Broken Economy","type":3,"slug":"broken-economy"}}}`

Editor

# Broken Economy

easy

In a country of novice government, the economic system is changed where only coins are used that too of various denominations. Whenever a foreigner visits this country, they visit a money exchanger to get the currency of the same country. As the foreigner is unaware of the denomination of the country, the money exchange prefers to tell them the denomination which is the nearest maximum and nearest minimum to the denomination mentioned by the foreigner. In case they get the correct guess of the denomination, they are told the same denomination. The denominations are always quoted in ascending order. Example 1: In a country, 8 given denominations are as follows [5, 10, 15, 22, 33, 40, 42, 55] The foreigner asks for denomination 25. The money exchange tells them that denominations of 33 and 22 are available. Example 2: In a country, 5 given denominations are as follows [7, 14, 18, 25, 30] The foreigner asks for the denomination of 18. The money exchange tells them a denomination of 18 is available. You are required to print the values told by the money exchange to the foreigner. 1. You are given a number n, representing the size of array a. 2. You are given n numbers, representing elements of the array a. 3. You are given another number d. 4. You are required to find the ceil and floor of d in array a.

## Constraints

1 <= n <= 1000 -10^9 <= n1, n2, .. n elements <= 10^9 -10^9 <= d <= 10^9

## Format

### Input

A number n n1 n2 .. n number of elements A number d

### Output

A number representing ceil A number representing floor

## Example

Sample Input

```.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}10 1 5 10 15 22 33 40 42 55 66 34```

### Sample Output

```.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}40 33```

Question Video

Discussions

Show Discussion

Related Resources