이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; ++i)
#define Ford(i, a, b) for(int i = a; i >= b; --i)
#define Task "test"
#define ld long double
#define ll long long
#define X first
#define Y second
#define pb push_back
//#define Karma
using namespace std;
template <typename T> inline void Cin(T &x)
{
register char c;
for (c = getchar(); c < '0' || c > '9'; c = getchar());
for (x = 0; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
}
const int N = 2e5 + 7;
ll x[N], g[N], r[N], res, j, p;
int t[N], n, Maxv;
vector<ll> v;
void Update(int x, int val)
{
while(x <= Maxv)
{
t[x] = min(t[x], val);
x += (x & -x);
}
}
int Query(int x)
{
int res = Maxv;
while(x > 0)
{
res = min(res, t[x]);
x -= (x & -x);
}
return res;
}
void Enter()
{
Cin(n);
Maxv = 2 * n + 2;
fill_n(t, Maxv + 2, Maxv);
For(i, 1, n)
{
Cin(x[i]), Cin(g[i]), Cin(r[i]);
res = max(res, g[i]);
g[i] += g[i - 1], r[i] += r[i - 1];
v.pb(r[i - 1] - x[i]), v.pb(r[i] - x[i]);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
}
void Solve()
{
For(i, 1, n)
{
j = Query(lower_bound(v.begin(), v.end(), r[i] - x[i]) - v.begin() + 1);
if(j < Maxv) res = max(res, g[i] - g[j - 1]);
p = lower_bound(v.begin(), v.end(), r[i - 1] - x[i]) - v.begin() + 1;
Update(p, i);
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef Karma
freopen(Task".inp", "r", stdin);
freopen(Task".out", "w", stdout);
#endif // Karma
Enter();
Solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |