-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtraveltheskies.cpp
99 lines (88 loc) · 1.93 KB
/
traveltheskies.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
#define _USE_MATH_DEFINES
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <stack>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
struct flight
{
int src;
int dest;
int day;
int amount;
};
struct arrival
{
int airport;
int day;
int customers;
};
int main()
{
ll i, j, k;
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll airports, days, flights;
cin >> airports >> days >> flights;
flight temp;
vector<int> amount(airports, 0);
vector<vector<flight>> flightVec(days, vector<flight>());
vector<vector<arrival>> arrivalVec(days, vector<arrival>());
for(int i = 0; i < flights; i++)
{
cin >> temp.src >> temp.dest >> temp.day >> temp.amount;
temp.src--;
temp.dest--;
temp.day--;
flightVec[temp.day].push_back(temp);
}
arrival newArrival;
for(int i = 0; i < airports; i++)
{
for(int j = 0; j < days; j++)
{
cin >> newArrival.airport >> newArrival.day >> newArrival.customers;
newArrival.day--;
newArrival.airport--;
arrivalVec[newArrival.day].push_back(newArrival);
}
}
for(int i = 0; i < days; i++)
{
// Arrival phase
for(auto thisArrival : arrivalVec[i])
{
amount[thisArrival.airport] += thisArrival.customers;
}
// Check if flights can be resolved
for(auto thisFlight : flightVec[i])
{
amount[thisFlight.src] -= thisFlight.amount;
if(amount[thisFlight.src] < 0)
{
cout << "suboptimal\n";
return 0;
}
}
// If they can, move them along
for(auto thisFlight : flightVec[i])
{
amount[thisFlight.dest] += thisFlight.amount;
}
}
cout << "optimal\n";
return 0;
}