Skip to content

Commit d20a7a6

Browse files
committed
Added more problems
1 parent 3c0ce8c commit d20a7a6

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

DP1(Very important)/Royandcoin

22.6 KB
Binary file not shown.

DP1(Very important)/Royandcoin.cpp

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
3+
Name: Mehul Chaturvedi
4+
IIT-Guwahati
5+
6+
*/
7+
8+
/*
9+
PROBLEM STATEMENT
10+
First line contains N - number of coin boxes.
11+
Second line contains M - number of days. Each of the next M lines consists of two space separated integers L and R. Followed by integer Q - number of queries.
12+
Each of next Q lines contain a single integer X.a
13+
Output
14+
For each query output the result in a new line.
15+
Constraints
16+
1 ≤ N ≤ 1000000
17+
18+
1 ≤ M ≤ 1000000
19+
20+
1 ≤ L ≤ R ≤ N
21+
22+
1 ≤ Q ≤ 1000000
23+
24+
1 ≤ X ≤ N
25+
Sample Input
26+
7
27+
4
28+
1 3
29+
2 5
30+
1 2
31+
5 6
32+
4
33+
1
34+
7
35+
4
36+
2
37+
Sample Output
38+
6
39+
0
40+
0
41+
4
42+
43+
*/
44+
45+
#include <bits/stdc++.h>
46+
47+
using namespace std;
48+
49+
50+
int main( int argc , char ** argv )
51+
{
52+
ios_base::sync_with_stdio(false) ;
53+
cin.tie(NULL) ;
54+
55+
int n, m;
56+
cin>>n>>m;
57+
vector<int> s(n+1, 0);
58+
vector<int> e(n+1, 0);
59+
60+
vector<int> buffer(n+1, 0);
61+
62+
63+
for (int i = 0; i < m; ++i)
64+
{
65+
int a, b;
66+
cin>>a>>b;
67+
68+
s[a]++;
69+
e[b]++;
70+
}
71+
72+
for (int i = 1; i < n+1; ++i)
73+
{
74+
buffer[i] = s[i] - e[i-1] + buffer[i-1];
75+
}
76+
77+
//Will store ki i coins kitne boxes me hai
78+
vector<int> coins(n+1,0);
79+
for (int i = 1; i < n+1; ++i)
80+
{
81+
coins[buffer[i]]++;
82+
}
83+
84+
for (int i = n-1; i >= 0; --i)
85+
{
86+
coins[i] += coins[i+1];
87+
}
88+
89+
int q;
90+
cin>>q;
91+
92+
for (int i = 0; i < q; ++i)
93+
{
94+
int temp;
95+
cin>>temp;
96+
cout << coins[temp] << '\n';
97+
}
98+
99+
100+
101+
return 0 ;
102+
103+
104+
105+
}

DP1(Very important)/Test.txt

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
3
2-
1 2 3
1+
7
2+
4
3+
1 3
4+
2 5
5+
1 2
6+
5 6
7+
4
8+
1
9+
7
10+
4
11+
2

DP1(Very important)/a.out

-13.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)