跳到正文

题解

AT_abc352_c 题解

Vitamin_B约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年5月6日
收录
2025年12月12日
更新
2026年11月7日
篇幅
约 1 分钟

版本

  1. v1当前

思路

这是本人遇到的最简单 ABC-C。

nn 个巨人叠罗汉,其实就是所有巨人的肩膀高度加最上面的头高度,即 ∑ai+bn−an\sum a_i+b_n-a_n,要使高度最大,就选择头最长的巨人在最上面,即 ∑ai+max⁡(bi−ai)\sum a_i+\max(b_i-a_i)。

代码

C++
# include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
int n, x, y, maxx;
ll sum;
int main () {
	ios::sync_with_stdio (0);
	cin.tie (0);
	cout.tie (0);
	cin >> n;
	while (n --)
		cin >> x >> y, sum += x, maxx = max (maxx, y - x);
	cout << maxx + sum;
	return 0;
}
原文