Skip to content

Commit e4b79ba

Browse files
authored
Merge pull request ashutosh97#136 from Adityajain732/master
Mislove Has Lost an Array
2 parents f033ff2 + 98ede3e commit e4b79ba

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Mislove had an array a1, a2, ⋯, an of n positive integers, but he has lost it. He only remembers the following facts about it:
2+
3+
1)The number of different numbers in the array is not less than l and is not greater than r.
4+
2)For each array's element ai either ai=1 or ai is even and there is a number ai/2 in the array.
5+
6+
For example, if n=5, l=2, r=3 then an array could be [1,2,2,4,4] or [1,1,1,1,2]; but it couldn't be [1,2,2,4,8] because this array contains 4 different numbers; it couldn't be [1,2,2,3,3] because 3 is odd and isn't equal to 1; and it couldn't be [1,1,2,2,16] because there is a number 16 in the array but there isn't a number 16/2=8.
7+
8+
According to these facts, he is asking you to count the minimal and the maximal possible sums of all elements in an array.
9+
10+
Input-1
11+
4 2 2
12+
Output
13+
5 7
14+
Input-2
15+
5 1 5
16+
Output
17+
5 31
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
int main()
4+
{
5+
long long int i,mini=1,mine=0,maxi=1,maxo=0,n,s,e;
6+
cin>>n>>s>>e;
7+
8+
for(i=1;i<=s-1;i++)
9+
{
10+
mini=2*mini;
11+
mine+=mini;
12+
}
13+
mine+=n-s+1;
14+
15+
for(i=1;i<=e-1;i++)
16+
{
17+
maxi=2*maxi;
18+
maxo+=maxi;
19+
}
20+
maxo+=1;
21+
22+
23+
maxo+=(n-e)*(maxi);
24+
cout<<mine<<" "<<maxo;
25+
return 0;
26+
}

0 commit comments

Comments
 (0)