Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- vector<vector<int> > a, gr;
- vector<int> ans;
- vector<bool> used;
- int n;
- void dfs(int v){
- used[v] = true;
- for (int i : gr[v]){
- if (!used[i]){
- dfs(i);
- }
- }
- ans.push_back(v);
- }
- int main(){
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> n;
- a.resize(n);
- gr.resize(n);
- used.resize(n);
- a.assign(n, vector<int>(4));
- for (int i = 0; i < n; ++i){
- cin >> a[i][0] >> a[i][1] >> a[i][2] >> a[i][3];
- }
- for (int i = 0; i < n; ++i){
- for (int j = 0; j < n; ++j){
- if (i == j){
- continue;
- }
- if (a[i][0] > a[j][1] || a[i][1] < a[j][0]){
- continue;
- }
- if (a[i][0] < a[j][0] && a[i][1] > a[j][1]){
- if (a[j][2] == a[i][2] + (a[j][0] - a[i][0]) * a[i][3]){
- if (a[j][2]+a[j][3] >= a[j][3] + a[i][2] + (a[j][0] - a[i][0]) * a[i][3]){
- gr[i].push_back(j);
- }
- }else if (a[j][2] > a[i][2] + (a[j][0] - a[i][0]) * a[i][3]){
- gr[i].push_back(j);
- }
- continue;
- }
- if (a[i][0] >= a[j][0]){
- if (a[i][2] == a[j][2]+(a[i][0] - a[j][0]) * a[j][3]){
- if (a[i][2]+a[i][3] < a[j][3]+a[j][2]+(a[i][0] - a[j][0]) * a[j][3]){
- gr[i].push_back(j);
- }
- }
- else if (a[i][2] < a[j][2]+(a[i][0] - a[j][0]) * a[j][3]){
- gr[i].push_back(j);
- }
- }else{
- if (a[i][2]+((a[i][1]-a[i][0])*a[i][3]) < a[j][2]+(a[i][1] - a[j][0]) * a[j][3]){
- gr[i].push_back(j);
- }
- }
- }
- }
- for (int i = 0; i < n; ++i){
- if (!used[i]){
- dfs(i);
- }
- }
- reverse(ans.begin(), ans.end());
- for (int i:ans){
- cout << i+1 << ' ';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement