QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#785787 | #9730. Elevator II | Proaes | WA | 0ms | 3620kb | C++17 | 2.2kb | 2024-11-26 19:12:20 | 2024-11-26 19:12:26 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
using pii = pair<int, int>;
void solve()
{
ll n, f, ans = 0;
cin >> n >> f;
multiset<int> s;
vector<pii> seg(n);
vector<int> path, vis(n + 1, 0);
for (auto &[x, y] : seg)
cin >> x >> y;
sort(seg.begin(), seg.end(), [&](pii u, pii v)
{ return u.second < v.second; });
int st = -1;
for (int i = 0; i < n; i++)
if (seg[i].first <= f && f <= seg[i].second)
{
st = i;
break;
}
if (st == -1)
{
for (int i = 0; i < n; i++)
if (f <= seg[i].second)
s.insert(i);
if (s.size())
{
st = *s.begin();
s.erase(st);
ans += seg[st].first - f;
}
}
else
{
for (int i = 0; i < n; i++)
if (i != st && seg[st].second <= seg[i].second)
s.insert(i);
}
if (st != -1)
{
vis[st] = 1;
path.push_back(st);
ans += seg[st].second - seg[st].first;
}
while (s.size())
{
while (s.size() && seg[*s.begin()].second < seg[st].second)
s.erase(s.begin());
if (s.size())
{
if (seg[*s.begin()].first > seg[st].second)
ans += seg[*s.begin()].first - seg[st].second;
st = *s.begin();
vis[st] = 1;
path.push_back(st);
ans += seg[st].second - seg[st].first;
s.erase(st);
}
}
vector<int> a;
for (int i = 0; i < n; i++)
if (!vis[i])
a.push_back(i);
sort(a.begin(), a.end(), [&](int u, int v)
{ return seg[u].first > seg[v].first; });
for (auto &i : a)
{
path.push_back(i);
ans += seg[i].second - seg[i].first;
}
cout << ans << endl;
for (auto &i : path)
cout << i + 1 << " ";
cout << endl;
}
int main()
{
#ifdef x3ea
freopen("in.txt", "r", stdin);
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int _ = 1;
cin >> _;
for (; _; _--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
11 1 2 3 4 5 2 1
result:
wrong answer Participant declares the cost to be 11, but the plan actually costs 12 (test case 1)