#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define F first
#define S second
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define pipii pair<int, pair<int, int>>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes() cout << "Yes" << endl
#define no() cout << "No" << endl
#define gcd __gcd
int lcm(int a, int b){
return a / gcd(a , b) * b;
}
bool isPalindrome(string s){
string x = s;
reverse(x.begin(), x.end());
return x == s;
}
bool isPrime(int n){
if(n < 2) return false;
if(n == 2) return true;
if(n % 2 == 0) return false;
for(int i = 3;i <= sqrt(n);i += 2){
if(n % i == 0) return false;
}
return true;
}
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const int MAX = 1e3 + 5;
int dp[MAX][MAX];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
signed main() {
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
int a[n + 1], b[n + 1];
vector<pii> vt;
for(int i = 1;i <= n;i++){
cin >> a[i] >> b[i];
vt.push_back({a[i], b[i]});
}
sort(all(vt));
int sum = vt[0].S, x = vt[0].F, y = vt[0].F;
int ans = sum - x + y;
for(int i = 1;i < vt.size();i++){
sum += vt[i].S;
x = max(x, vt[i].F);
y = min(y, vt[i].F);
ans = max(ans, sum - x + y);
}
cout << ans << endl;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |