-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoke.cpp
112 lines (111 loc) · 2.63 KB
/
coke.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
#include <bits/stdc++.h>
using namespace std;
int main() {
std::cout.sync_with_stdio(false);
cin.tie(0);
int t;
cin>>t;
for(int i=0;i<t;i++)
{
int n,q,l,r,k;
cin>>n>>q>>k>>l>>r;
vector <pair<int,int>> v;
for(int j=0;j<n;j++)
{
int c,p;
cin>>c>>p;
v.push_back(make_pair(p,c));
}
sort(v.begin(),v.end());
int arr[q+1];
arr[0]=0;
for(int j=1;j<=q;j++)
{
arr[j]=-1;
}
int count=q;
int lower=-1,upper=-2;
for(int j=0;j<n;j++)
{
if(v[j].second>r)
{
if(k>=l && k<=r)
{
lower=v[j].second-r;
upper=q;
}
else if(k<l)
{
lower=v[j].second-r;
upper=v[j].second-l;
if(upper>q)
{
upper=q;
}
}
}
else if(v[j].second<l)
{
if(k>=l && k<=r)
{
lower=l-v[j].second;
upper=q;
}
else if(k>r)
{
lower=l-v[j].second;
upper=r-v[j].second;
if(upper>q)
{
upper=q;
}
}
}
else if(v[j].second>=l && v[j].second<=r)
{
if(k>r)
{
lower=1;
upper=r-v[j].second;
if(upper>q)
{
upper=q;
}
}
else if(k<l)
{
lower=1;
upper=v[j].second-l;
if(upper>q)
{
upper=q;
}
}
else
{
lower=1;
upper=q;
}
}
for(int index=lower;index<=upper;index++)
{
if(arr[index]==-1)
{
arr[index]=v[j].first;
}
count--;
}
lower=-1,upper=-2;
if(count==0)
{
break;
}
}
for(int index=1;index<=q;index++)
{
cout<<arr[index]<<" ";
}
cout<<"\n";
}
return 0;
}