QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#742832#9730. Elevator IIshenchuan_fanWA 0ms3528kbC++201.2kb2024-11-13 17:25:352024-11-13 17:25:43

Judging History

你现在查看的是最新测评结果

  • [2024-11-13 17:25:43]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3528kb
  • [2024-11-13 17:25:35]
  • 提交

answer

/* 
	24 HZ E
*/
#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;
void solve() {
	int n, f;
	cin >> n >> f;
	multiset <PII> L;
	multiset <PII> R;
	vector <PII> a(n + 1);
	for(int i = 1; i <= n; i++){
		cin >> a[i].x >> a[i].y;
		L.insert({a[i].x, i});
	}
	int ans = 0;
	R.insert({f, -1});
	vector <int> perm;
	while(R.size() && L.size()){
		PII t = *R.rbegin();
		//cout << t.x << " " << t.y << "\n";
		if(t.y != -1) perm.push_back(t.y);
		auto it = L.lower_bound({t.x, 0});
		if(it == L.end()){
			R.erase(R.find(t));
			PII bg = *L.begin();
			R.insert({a[bg.y].y, bg.y});
			ans += a[bg.y].y - bg.x;
			L.erase(L.find(bg));
			continue;
		}else{
			PII to = *it;
			ans += to.x - t.x;
			ans += a[to.y].y - to.x;
			R.insert({a[to.y].y, to.y});
			L.erase(L.find(to));
		}
	}
	PII t = *R.rbegin();
	perm.push_back(t.y);
	cout << ans << "\n";
	for(auto p: perm) cout << 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: 3528kb

input:

2
4 2
3 6
1 3
2 7
5 6
2 5
2 4
6 8

output:

11
3 2 1 4 
5
2 -1 

result:

wrong answer Integer parameter [name=a_i] equals to -1, violates the range [1, 2] (test case 2)