This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <string>
#include <set>
#include <map>
#include <algorithm>
#include <fstream>
#include <cmath>
#include <queue>
#include <stack>
#include <cassert>
#include <cstring>
#include <climits>
#include <functional>
#include<cstdlib>
//#include "arc.h"
//#include "dreaming.h"
using namespace std;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long LL;
const int MAXN = 5e5 + 11;
using ll = long long;
const ll mod1 = 1e9 + 7;
const ll mod2 = 1000000021;
const ll P = 31;
/*
void setIO(string name = "") {
cin.tie(0)->sync_with_stdio(0); // see /general/fast-io
if ((name.size())) {
freopen((name + ".in").c_str(), "r", stdin); // see /general/input-output
freopen((name + ".out").c_str(), "w", stdout);
}
}
*/
int n;
vector<pair<ll, ll>> vp;
vector<ll> arr;
ll mn;
ll sum;
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
//setIO("time");
cin >> n;
for (int i = 1; i <= n; i++)
{
ll a, b;
cin >> a >> b;
vp.push_back({ a,b });
}
sort(vp.begin(), vp.end());
for (int i = 0; i < n; i++)
{
if (i > 0)
{
arr.push_back(-(vp[i].first - vp[i-1].first));
}
arr.push_back(vp[i].second);
}
ll ans = 0;
for (int i = 0; i < arr.size(); i++)
{
if (sum < 0)
sum = 0;
sum += arr[i];
ans = max(ans, sum);
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
art.cpp: In function 'int main()':
art.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for (int i = 0; i < arr.size(); i++)
| ~~^~~~~~~~~~~~
# | 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... |