-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshinde.cpp
90 lines (69 loc) · 1.43 KB
/
shinde.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
// FINAL
#include <bits/stdc++.h>
using namespace std;
void RCB(int numBoxes, int *start, int *end, int *queries, int q)
{
int *coins = new int[numBoxes+1];
coins[1] = start[1];
for(int i=2; i<= numBoxes; i++)
{
coins[i] = coins[i-1] + start[i] - end[i-1];
}
int *numberOfCoins = new int[numBoxes+1];
for(int i=1; i<=numBoxes; i++)
{
numberOfCoins[i] = 0;
}
for(int i=1; i<=numBoxes; i++)
{
numberOfCoins[coins[i]]++;
}
for(int i=numBoxes; i>=2; i--)
{
numberOfCoins[i-1] += numberOfCoins[i];
}
for(int i=0; i<q; i++)
{
if(queries[i] > numBoxes){
cout<<0<<endl;
}
else
cout << numberOfCoins[queries[i]] << endl;
}
delete coins;
delete numberOfCoins;
return;
}
int main()
{
int n;
cin >> n;
int m;
cin >> m;
int *start = new int[n+1];
int *end = new int[n+1];
int s, e;
for(int i=1; i<=n; i++)
{
start[i] = 0;
end[i] = 0;
}
for(int i=0; i<m; i++)
{
cin >> s >> e;
start[s]++;
end[e]++;
}
int q;
cin >> q;
int *queries = new int[q];
for(int i=0; i<q; i++)
{
cin >> queries[i];
}
RCB(n, start, end, queries, q);
delete queries;
delete start;
delete end;
return 0;
}