# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
335936 | Killer2501 | Art Exhibition (JOI18_art) | C++14 | 222 ms | 24940 KiB |
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<bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define pll pair<ll, ll>
#define pb push_back
#define pii pair<ll ,pll>
#define task "C"
using namespace std;
const int N = 5e5+5;
const int mod = 1e9+7;
ll n, t, m, k, a[N], b[N], ans, tong, u, v;
string s;
bool ok;
pll p[N];
struct dang
{
ll x, y, id;
dang(){}
dang(ll x, ll y, ll id): x(x), y(y), id(id){}
};
bool cmp(const dang& u, const dang& v)
{
return ((u.x < v.x) || (u.x == v.x && u.y < v.y));
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> p[i].fi >> p[i].se;
}
sort(p+1, p+1+n);
ans = p[1].se;
a[1] = p[1].se;
k = -p[1].fi;
for(int i = 2; i <= n; i ++)
{
a[i] = a[i-1] + p[i].se;
ans = max(p[i].se, max(ans, a[i] - p[i].fi - k));
//cout << a[i] - p[i].fi <<" "<<k<<'\n';
k = min(k, a[i-1] - p[i].fi);
}
cout << ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message (stderr)
# | 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... |