Transmission Door
Ice Cream Parlorauthored by Dheeraj on Mar
Problem Statement
Sunny and Johnny together has M dollars they want to spend on ice cream. The parlor offers N flavors, and they want to choose. Flavors So, they end up spending the whole Amoun T.
You is given the cost of these flavors. The cost of theIth Flavor is denoted by cI.. You have to display the indices of the flavors whose sum is M.
Input Format
The first line of the input containsT;TTest cases follow.
Each test case follows the format detailed below:the first line containsM. The second line containsN. The third line containsNspace-separated integers denoting the price of each flavor. Here, thei t h integer denotes < Span id= "mathjax-span-829" class= "math" > c i .
Output Format
Output of the integers, each of which is a valid index of a flavor. The lower index must is printed first. Indices is indexed from 1 to N.
Constraints
1≤T≤
2≤M≤10000
2≤N≤10000
1≤c I ≤10000,where i∈[1,N]
The prices of any and all the same and each test case have a unique solution.
Sample Input
2451 4 5 3 2442 2 4 3
Sample Output
1 41 2
Explanation
The sample input has both test cases.
For the 1st, the amount M = 4 and there is 5 flavors at the store. The flavors indexed at 1 and 4 sum up to 4.
For the 2nd test case, the amount M = 4 and the flavors indexed at 1 and 2 sum up to 4.
Solution
Simple question.
Construct the index array using the cost array given by the topic,Index[i] to indicate where i first appeared in the cost array.
Implementation
#include <bits/stdc++.h>using namespace std;Const int N(1e4+5);int Idx[n];int Main(){Freopen ("in", "R", stdin);int T; Cin>>T; for(int N, m, Id1, Id2; T--; memset (idx, 0, sizeof(IDX))) {Cin>>m>>N; for(int I=1, C; I<=N; I++){Cin>>C;if(c>=m) Continue;//error-proneif(!Idx[c]) Idx[c]=i;if(Idx[m-c]&&idx[m-c]!=i) {ID1=idx[m-c], Id2=i;//error-prone}}cout<<ID1<<"'<<Id2<<Endl;}}
Where the note Error-prone is beginning to write wrong.
1. My writing is to read into the side of the processing, and sometimes will not finish reading the answer, then it is easy to get a break ;
2. For this problem
2.1 To pre-c>=m the situation
2.2 How to deal with the same cost flavor
Hackerrank Ice Cream Parlor