QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#760856 | #9730. Elevator II | yihang_01# | WA | 0ms | 3596kb | C++20 | 2.2kb | 2024-11-18 19:48:30 | 2024-11-18 19:48:30 |
Judging History
answer
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <vector>
#define int long long
using namespace std;
struct node{
int x , y;
int id;
node(int x , int y , int id){
this->x = x;
this->y = y;
this->id = id;
}
bool operator < (const node &a)const{
if(x == a.x){
return y < a.y;
}else{
return x < a.x;
}
}
};
bool cmp(const node & a ,const node & b){
if(a.y == b.y){
return a.x < b.x;
}else{
return a.y > b.y;
}
}
vector<node> mp;
list<node> ned1;
vector<node> ned2;
map<int , int > id_ans;
void solve(){
mp.clear();
ned1.clear();
ned2.clear();
id_ans.clear();
int n , tmpx , tmpy , initf;
int nedval = 0;
cin >> n >> initf;
for(int i = 1;i<=n;i++){
cin >> tmpx >> tmpy;
nedval += tmpy - tmpx;
mp.push_back(node(tmpx , tmpy , i));
}
sort(mp.begin() , mp.end());
for(int i = 0;i<n;i++){
if(mp[i].y >= initf)
ned1.push_back(mp[i]);
else
ned2.push_back(mp[i]);
}
int nowend = initf;
int extraval = 0;
for(auto it = ned1.begin();it!= ned1.end() ;){
int ittx = it->x;
int itty = it->y;
int ittid = it->id;
if(itty <= nowend){
ned2.push_back(node(ittx, itty , ittid));
it = ned1.erase(it);
continue;
}
if(nowend < ittx){
extraval += ittx - nowend;
}
nowend = itty;
it ++ ;
}
sort(ned2.begin() , ned2.end() , cmp);
int ans = 0;
for(auto it : ned1){
id_ans[it.id] = ++ans;
}
for(auto it : ned2){
id_ans[it.id] = ++ans;
}
cout << nedval + extraval << endl;
for(int i = 1;i<=n;i++){
cout << id_ans[i] << " ";
}
cout <<endl;
return ;
}
signed main(){
int t;
ios::sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
cin >> t;
while(t--){
solve();
}
}
/*
2
4 2
3 6
1 3
2 7
4 5
2 5
2 4
6 8
*/
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
2 4 2 3 6 1 3 2 7 5 6 2 5 2 4 6 8
output:
11 3 1 2 4 5 2 1
result:
wrong answer Participant declares the cost to be 11, but the plan actually costs 13 (test case 1)