MX-J8 A.竹竿90pts 求助
  • 板块题目总版
  • 楼主TigerTanWQY
  • 当前回复6
  • 已保存回复6
  • 发布时间2024/10/20 12:18
  • 上次更新2024/10/20 14:12:20
查看原帖
MX-J8 A.竹竿90pts 求助
617314
TigerTanWQY楼主2024/10/20 12:18

WA on #1, read 9, expect 10.

#include <iostream>
#include <algorithm>
using namespace std;
using LL = long long;

pair<int, int> a[100003];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> a[i].first >> a[i].second;
	sort(a + 1, a + n + 1);
	int tag = max(a[1].second, a[1].first - a[1].second), id = 1;
	for(int i = 2; i <= n; ++i) {
		const int w = max(a[i].second, a[i].first - a[i].second);
		if(w > tag) {
			tag = w;
			id = i;
		} else if(w == tag && a[i].first > a[id].first)
			id = i;
	}
	LL ans = 0;
	for(int i = 1; i <= n; ++i)
		if(i != id)
			ans = max({ans, (LL)tag + a[i].second, (LL)tag + a[i].first - a[i].second});
	cout << ans << endl;
	return 0;
}
2024/10/20 12:18
加载中...