-
Notifications
You must be signed in to change notification settings - Fork 0
/
2_Thief_Logistics.cpp
60 lines (53 loc) · 1.56 KB
/
2_Thief_Logistics.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
/*
CodeZest22 Div2 Solutions
Question 2 - Thief Logistics
Problem Statement-
You are a thief who has broken into a jewellery store.
The store has N pieces of jewellery called Jewel 1 through N, and you have X boxes called Box 1 through X.
Each Jewel j has a size of Sj and a value of Vj. Box j can contain a jewel whose size is of at most Zj. It cannot contain two or more jewels.
In the input you will be given Q queries. In each query, you are provided with two integers A and B, solve the following problem:
Out of the X boxes, B-A+1 boxes,i.e., Box A, A+1,..., B, have become unavailable.
Find the maximum possible total value of a set of jewels that we can put into the remaining boxes simultaneously.
*/
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,x,q;
cin>>n>>x>>q;
vector<pair<int,int>> vec(n);
for(int i=0;i<n;i++){
int s,v;
cin>>s>>v;
vec.push_back(make_pair(v,s));
}
sort(vec.rbegin(),vec.rend());
vector<int> box(x);
for(int i=0;i<x;i++)
{
cin>>box[i];
}
while(q--)
{
int a,b;
cin>>a>>b;
a--,b--;
multiset<int> ms;
for(int i=0;i<x;i++)
{
if(i<a || i>b)
{
ms.insert(box[i]);
}
}
int ans=0;
for(int i=0;i<n;i++){
auto itr = ms.lower_bound(vec[i].second);
if(itr != ms.end()){
ans+=vec[i].first;
ms.erase(itr);
}
}
cout<<ans<<"\n";
}
return 0;
}