이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define f(i, a, b) for(ll i = a; i <= b; ++i)
#define ff(i, a, b) for(ll i = a; i < b; ++i)
#define F(i, a, b) for(ll i = a; i >= b; --i)
#define FF(i, a, b) for(ll i = a; i > b; --i)
#define x first
#define y second
#define X real()
#define Y imag()
using namespace std;
typedef complex<ll> P;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
const int N = 5e5+7;
ll n, ans = 0, b[N], f[N], rmq[N][19];
ii a[N];
ll get_min(ll post){
ll loga;
if(loga > 1) loga = log2(post-1);
else loga = 0;
return min(rmq[0][loga], rmq[post-(1<<loga)][loga]);
}
signed main(){
// freopen("PERFECT1.inp","r",stdin);
// freopen("PERFECT1.out","w",stdout);
scanf("%lld", &n);
f(i,1,n){
scanf("%lld %lld", &a[i].x, &a[i].y);
}
sort(a+1, a+1+n);
rmq[0][0] = -a[1].x;
f[0] = 0;
f(i,1,n){
f[i] = f[i-1] + a[i].y;
b[i] = f[i]-a[i].x;
if(i != n){
rmq[i][0] = f[i]-a[i+1].x;
}
}
f(j,1,18){
ff(i,0,n){
if(i + (1<<j) - 1 < n){
rmq[i][j] = min(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
}
}
}
f(i,1,n){
ans = max(ans, b[i]-get_min(i));
}
printf("%lld", ans);
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &n);
~~~~~^~~~~~~~~~~~
art.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &a[i].x, &a[i].y);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp: In function 'long long int get_min(long long int)':
art.cpp:22:2: warning: 'loga' is used uninitialized in this function [-Wuninitialized]
if(loga > 1) loga = log2(post-1);
^~
# | 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... |