# 塔台超频## 题目描述在一条笔直的马路上有 $n$ 个塔台它们被依次标号为 $1 2 cdots n$分别处于距离马路起点 $a _ 1 a _ 2 cdots a _ n$$a _ 1 a _ 2 cdots a _ n$的位置。每个塔台初始时有一个通讯半径 $b _ 1 b _ 2 cdots b _ n$这代表对于 $i$ 号塔台其可以与 $a _ i - b _ i a _ i
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> towers(n);
for (int i = 0; i < n; i++) {
cin >> towers[i].first >> towers[i].second;
}
sort(towers.begin(), towers.end());
int minVoltage = 0;
int maxRadius = towers[0].second;
for (int i = 1; i < n; i++) {
int voltage = max(0, towers[i].first - towers[i-1].first - maxRadius);
minVoltage = max(minVoltage, voltage);
maxRadius = max(maxRadius, towers[i].second);
}
cout << minVoltage << endl;
return 0;
}
``
原文地址: https://www.cveoy.top/t/topic/h4n2 著作权归作者所有。请勿转载和采集!