이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
const int maxn = 300009;
int n;
long long e[maxn], E[maxn];
long long g[maxn], G[maxn];
long long x[maxn], X[maxn];
long long a[maxn], b[maxn], f[maxn];
void upd(long long x, long long d){
while(x <= 2*n+1){
f[x] = min(f[x], d);
x += (x & -x);
}
}
long long cnt(long long x){
long long ans = 1e18;
while(x){
ans = min(ans, f[x]);
x -= (x & -x);
}
return ans;
}
main(){
cin >> n;
for(long long i = 1; i <= n; i++){
cin >> x[i] >> g[i] >> e[i];
X[i] = x[i] ;
G[i] = g[i] + G[i - 1];
E[i] = e[i] + E[i - 1];
}
//E[r] - E[l] > X[r] - X[l + 1] ---> G[r] - G[l]
vector<pair<long long,long long> > v;
for(long long i = 0; i <= n; i++){
v.push_back({E[i] - X[i], i + n + 1});
v.push_back({E[i] - X[i + 1], i});
}
sort(v.begin(), v.end());
for(long long i = 0; i < v.size(); i++)
if(v[i].second <= n) b[v[i].second] = i + 1;
else a[v[i].second - n - 1] = i + 1;
for(long long i = 1; i <= 3*n+1; i++)
f[i] = 1e18;
long long ans = 0;
for(long long i = 0; i <= n; i++){
long long T = cnt(a[i] - 1);
ans = max(ans, G[i] - T);
upd(b[i], G[i]);
}
cout << ans << endl;
}
컴파일 시 표준 에러 (stderr) 메시지
divide.cpp:23:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
divide.cpp: In function 'int main()':
divide.cpp:39:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(long long i = 0; i < v.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... |