This repository has been archived by the owner on Jun 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
food_delivery.cpp
92 lines (89 loc) · 1.87 KB
/
food_delivery.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
#include <iostream>
#include <queue>
#include <vector>
#include <tuple>
#include <algorithm>
#include <map>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> goals(m);
for (int i = 0; i < m; ++i)
{
cin >> goals[i];
}
vector<int> goals_sorted = goals;
sort(goals_sorted.begin(), goals_sorted.end());
queue<int> gf, dm;
int cnt = 0;
int got = 0, idx = 0;
map<int, int> res;
while (n--)
{
int c;
cin >> c;
if (c == 1)
{
int r, p;
cin >> r >> p;
if (r == 1)
{
gf.push(p);
}
else if (r == 2)
{
dm.push(p);
}
}
else if (c == 2)
{
if (dm.empty())
{
got += gf.front();
gf.pop();
}
else if (gf.empty())
{
got += dm.front();
dm.pop();
}
else
{
int dt, gt;
dt = dm.front();
gt = gf.front();
if (dt < gt)
{
got += dt;
dm.pop();
}
else if (gt < dt)
{
got += gt;
gf.pop();
}
else
{
got += gt;
gf.pop();
}
}
++cnt;
while (idx < m && got >= goals_sorted[idx])
{
res[goals_sorted[idx]] = cnt;
++idx;
}
}
}
for (int i : goals)
{
auto r = res[i];
cout << (r == 0 ? -1 : r) << ' ';
}
return 0;
}