forked from Mugdha-Hazra/PrepBytes-questions
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Find Money.cpp
154 lines (142 loc) · 1.78 KB
/
Find Money.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Find Money
There is a straight path having
N
small boxes of size
1
∗
1
. Each box contains a certain amount of money, Manish directly jumps to a certain box having value
K
. Now as Manish is not good in maths help him, to find the total money on his left side and right side.
Note:- Consider the first occurrence of
K
.
Input Format
First-line contains an integer
T
, representing the number of test cases.
Next
T
lines contain two space-separated integers
N
and
K
.
The next line contains
N
space-separated integers representing the amount of money in each box of size
1
∗
1
.
Output Format
For each test case
T
, print the desired output in a new line. If a box with money =
K
is not present print
0
.
Constraints
1
<=
T
<=
1000
1
<=
N
,
K
<=
10
5
Time Limit
1 second
Example
Input
4
5 8
2 5 8 3 7
15 89
1 3 2 4 5 89 5 6 2 3 8 1 2 9 7
25 13
1 2 1 2 3 1 4 9 18 7 1 2 3 4 2 3 6 8 5 12 13 4 2 5 15
50 1999
1 2 1 2 3 1 4 9 18 7 1 2 3 4 2 3 6 8 5 12 13 4 2 5 15 1 2 1 2 3 1 4 9 18 7 1 2 3 4 2 3 6 8 5 12 13 4 2 5 15
Output
7 10
15 43
94 26
0
Sample test case explanation
For Input
1
Since
8
is in the path so the sum of the left and right side is
7
and
10
.
For Input
2
Since
89
is in the path so the sum of the left and right side is
15
and
43
.
For Input
3
Since
13
is in the path so the sum of the left and right side is
94
and
26
.
For Input
4
Since
1999
is not in the path so
0
.
*/
#include <bits/stdc++.h>
using namespace std;
int main()
{int t;
cin>>t;
while(t>0)
{ int i,n,k,a[10000000],g=0,h=0,p=0,m=0;
cin>>n>>k;
for(i=0;i<n;i++)
{
cin>>a[i];
} //int p=0;
for(i=0;i<n;i++)
{
if(a[i]==k)
{ m=i;
p=1;
break;
}
}
if(p>0)
{
for(i=0;i<n;i++)
{
(i>m?g+=a[i]:h+=a[i]);
}
cout<<h-k<<" "<<g<<"\n";
}
else
cout<<"0\n";
t--;
}
return 0;
}