제출 #285559

#제출 시각아이디문제언어결과실행 시간메모리
285559SamAndRoller Coaster Railroad (IOI16_railroad)C++17
11 / 100
2073 ms5880 KiB
#include "railroad.h"
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int N = 200005;
struct ban
{
    int s, t;
};

int n;
ban a[N];

bool operator<(const ban& a, const ban& b)
{
    if (a.s < b.s)
        return true;
    if (a.s > b.s)
        return false;
    return a.t < b.t;
}

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t)
{
    n = sz(s);
    for (int i = 1; i <= n; ++i)
    {
        a[i].s = s[i - 1];
        a[i].t = t[i - 1];
    }
    sort(a + 1, a + n + 1);
    ll ans = 0;
    for (int i = 1; i < n; ++i)
    {
        ans += max(0, a[i].t - a[i + 1].s);
    }
    do
    {
        ll yans = 0;
        for (int i = 1; i < n; ++i)
        {
            yans += max(0, a[i].t - a[i + 1].s);
        }
        ans = min(ans, yans);
    } while (next_permutation(a + 1, a + n + 1));

    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...