QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#744010 | #9730. Elevator II | shenchuan_fan | WA | 0ms | 3616kb | C++20 | 1.8kb | 2024-11-13 20:35:00 | 2024-11-13 20:35:03 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 1e7 + 10, M = 5010, mod = 998244353;
const int inf = 1e9;
struct node{
int x, y, id;
};
void solve() {
int n, f;
cin >> n >> f;
int ans = 0;
vector <node> a(n + 1);
for(int i = 1; i <= n; i++){
cin >> a[i].x >> a[i].y;
a[i].id = i;
ans += a[i].y - a[i].x;
}
//cout << ans << "\n";
sort(a.begin() + 1, a.end(), [&](node a, node b){
return a.x < b.x;
});
multiset <int> R;
R.insert(f);
vector <int> nxt(n + 1);
map <int, vector<int>> mp;
/*for(int i = 1; i <= n; i++){
R.insert(a[i].y);
mp[a[i].y].push_back(a[i].id);
}*/
mp[f].push_back(0);
/*for(int i = 1; i <= n; i++){
auto [u, v, idx] = a[i];
cout << i << ": " << u << " " << v << " " << idx << "\n";
}
cout << "\n";*/
for(int i = 1; i <= n; i++){
auto [u, v, idx] = a[i];
auto it = R.lower_bound(u + 1);
if(it == R.end()){
auto it2 = prev(it);
int t = *it2;
ans += u - t;
R.erase(R.find(t));
nxt[mp[t].back()] = idx;
//cout << mp[t].back() << " " << idx << "\n";
mp[t].pop_back();
}
R.insert(v);
mp[v].push_back(idx);
}
/*for(int i = 0; i <= n; i++){
cout << nxt[i] << " \n"[ i == n ];
} */
set <int> unuse;
for(int i = 1; i <= n; i++){
unuse.insert(i);
}
for(int i = 0; i <= n; i++){
if(nxt[i] != 0){
unuse.erase(nxt[i]);
}
}
cout << ans << "\n";
int p = 0;
for(int i = 0; i < n; i++){
if(nxt[p] == 0){
p = *unuse.begin();
cout << p << " ";
unuse.erase(unuse.begin());
}else{
cout << nxt[p] << " ";
p = nxt[p];
}
}
cout << "\n";
}
signed main() {
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T = 1;
cin >> T;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3616kb
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)