Input The first line contains two integers N and S ( 1 <= N <= 10 ³ 1 <= S <= 10³), denoting the length of the list, and the target Sum. In the next line, there will be N integers a₁, a2,,a (1 ≤ a, ≤ 10) separated by space. Output Print two integers: the positions of the values [1 based indexing]. If there are several solutions, you may print any of them. If there are no solutions, print "IMPOSSIBLE". Sample Input 1 4 10 37 15 Sample Input 2 6 18 9 10 1 5 98 Sample Input 3 47 2468 Sample Input 4 3 12 612 Sample Output 1 12 Sample Output 2 15 [2 6 is also a valid answer] [print only one output] Sample Output 3 IMPOSSIBLE Sample Output 4 IMPOSSIBLE

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Only need the ans for 1. Solve this using python. For the problem, take sample input from the picture into a file called "input.txt" and save the output in the "output.txt" file.
Input
The first line contains two integers N and S ( 1 <= N <= 105 1 <=
S <= 10), denoting the length of the list, and the target Sum.
.,a (1 ≤ a S
In the next line, there will be N integers a₁, a2,
10) separated by space.
Output
Print two integers: the positions of the values [1 based
indexing]. If there are several solutions, you may print any of
them. If there are no solutions, print "IMPOSSIBLE".
Sample Input 1
4 10
37 15
Sample Input 2
6 18
9 10 1 5 98
Sample Input 3
47
2468
Sample Input 4
3 12
6 1 2
Sample Output 1
1 2
Sample Output 2
15
[2 6 is also a valid answer]
[print only one output]
Sample Output 3
IMPOSSIBLE
Sample Output 4
IMPOSSIBLE
Transcribed Image Text:Input The first line contains two integers N and S ( 1 <= N <= 105 1 <= S <= 10), denoting the length of the list, and the target Sum. .,a (1 ≤ a S In the next line, there will be N integers a₁, a2, 10) separated by space. Output Print two integers: the positions of the values [1 based indexing]. If there are several solutions, you may print any of them. If there are no solutions, print "IMPOSSIBLE". Sample Input 1 4 10 37 15 Sample Input 2 6 18 9 10 1 5 98 Sample Input 3 47 2468 Sample Input 4 3 12 6 1 2 Sample Output 1 1 2 Sample Output 2 15 [2 6 is also a valid answer] [print only one output] Sample Output 3 IMPOSSIBLE Sample Output 4 IMPOSSIBLE
Your little brother, Alice, is very fond of playing with
integers. One day, Alice was given a list of N integers by his
school teacher. Now, your brother wants to play a game with you.
Alice will give you an integer, S. You have to find if it is
possible to find two values from the list (at distinct
positions) whose sum is equal to S.
Now you are feeling very tired. So you decided to write a code,
so that it can give you the answer very quickly.
1) Can you write an O(n²) Solution to solve the problem?
2) Come up with an O(n) or 0 (nlogn) solution.
Transcribed Image Text:Your little brother, Alice, is very fond of playing with integers. One day, Alice was given a list of N integers by his school teacher. Now, your brother wants to play a game with you. Alice will give you an integer, S. You have to find if it is possible to find two values from the list (at distinct positions) whose sum is equal to S. Now you are feeling very tired. So you decided to write a code, so that it can give you the answer very quickly. 1) Can you write an O(n²) Solution to solve the problem? 2) Come up with an O(n) or 0 (nlogn) solution.
Expert Solution
steps

Step by step

Solved in 3 steps with 5 images

Blurred answer
Knowledge Booster
Map
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education