当前位置:网站首页>uva1467
uva1467
2022-07-24 02:59:00 【Stab the bear with a knife】
#include <iostream>
#include <istream>
#include <sstream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
const int maxn = 505;
int n, p;
struct Node {
int s, d;
bool operator<(const Node& input) {
return d < input.d;
}
}node[maxn];
int test(int x)
{
int t = 0, a = 0, b = 0, k = 0;
for (int i = 0; i <= p; ++i)
{
if (i == x) continue;
t += node[i].s;
k = max(0, t - node[i].d);
b = max(b, k);
if (b > a) swap(a, b);
}
t += node[x].s;
k = max(0, t - node[x].d);
b = max(b, k);
return a + b;
}
int main()
{
int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> node[i].s >> node[i].d;
}
sort(node, node + n);
int a = 0, b = 0, t = 0, v;
for (int i = 0; i < n; i++) {
t += node[i].s;
v = max(0, t - node[i].d);
if (v > b) {
b = v;
p = i;
}
if (b > a)swap(a, b);
}
int ans = a + b;
for (int i = 0; i < p; ++i)
ans = min(ans, test(i));
cout << ans << endl;
}
return 0;
}
边栏推荐
- Zone d'entraînement Web d'attaque et de défense (View source, get Post, robots)
- compostion-api(setup中) watch使用细节
- Ugui source code analysis - imaskable
- js传参时传入 string有数据;传入 number时没有数据;2[0]是对的!number类型数据可以取下标
- 老公,我们现在无家可归了
- [interview: concurrent Article 21: multithreading: activeness] deadlock, livelock, hunger
- 自定义kindeditor富文本默认的宽高
- 【HDLBits 刷题】Verilog Language(2)Vectors 部分
- Attack and defense world web practice area (webshell, command_execution, simple_js)
- Some properties of differential array operation
猜你喜欢

CMT 注册——Google Scholar Id,Semantic Scholar Id,和 DBLP Id

PMP first-hand data and information acquisition

Audio processing based on time-frequency diagram matlab

An introductory example of structure and combinatorial ideas in go language

compostion-api(setup中) watch使用细节

Recommendation system topic | recommendation system architecture and single domain cross domain recall model

Detailed explanation of wechat official account online customer service access methods and functions

Attack and defense world web practice area (webshell, command_execution, simple_js)

Hcip --- BGP comprehensive experiment
![js传参时传入 string有数据;传入 number时没有数据;2[0]是对的!number类型数据可以取下标](/img/4e/3d0c25d9579b6d5c00473048dbbd83.png)
js传参时传入 string有数据;传入 number时没有数据;2[0]是对的!number类型数据可以取下标
随机推荐
数据湖(十五):Spark与Iceberg整合写操作
go IO操作-文件读
kettle
Super complete PMP reference document summary
Detailed vector
js傳參時傳入 string有數據;傳入 number時沒有數據;2[0]是對的!number類型數據可以取下標
LCD1602 - binge 51
Go log package
Detailed explanation of wechat official account online customer service access methods and functions
Customize the default width and height of kindeditor rich text
开源量子开发框架 Cirq
让生活充满幸福感
The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
La chaîne entrante a des données lors de la transmission des paramètres JS; Aucune donnée n'a été transmise au numéro; 2 [0] Oui! Les données de type numéro peuvent être indexées
Uie: unified model of information extraction
Leetcode stack and queue questions
The simple use of ADB command combined with monkey is super detailed
Generate 13 bit barcode
JpaRepository扩展接口
Make life full of happiness