# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1127511 | anuar | Art Exhibition (JOI18_art) | C++20 | 0 ms | 320 KiB |
#include <bits/stdc++.h>
// using namespace __gnu_pbds;
using namespace std;
//====================================//
void io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void file(const char* in, const char* out) {
#ifndef ONLINE_JUDGE
freopen(in, "r", stdin);
freopen(out, "w", stdout);
#endif
}
//====================================//
int n;
pair<long long, long long> a[(int)5e5+1];
long long pref[(int)5e5+1];
long long check(long long M) {
long long res = 0;
for (int i = 1; i <= n; i++) {
int l = i, r = n, pos = i;
while (l<=r) {
int m = l+r >> 1;
if (a[m].first - a[i].first > M) {
r = m-1;
}
else {
l = m+1;
pos = m;
}
}
res = max(res, pref[pos] - pref[i-1]);
}
return res;
}
void rewenie() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i].first >> a[i].second;
}
sort(a+1, a+n+1);
for (int i = 1; i <= n; i++) {
pref[i] = pref[i-1] + a[i].second;
}
long long l = 0, r = 1e15+100;
for (int i = 1; i <= 100; i++) {
long long m1 = l + (r-l)/3;
long long m2 = r - (r-l)/3;
if (check(m1) - m1 > check(m2) - m2) {
r = m2;
}
else {
l = m1;
}
}
long long ans = 0;
int j = 0;
for (long long i = l; i <= r; i++) {
if (long long b = check(i) - i; b > ans) {
ans = max(ans, b);
j = i;
}
}
cout << ans;
// cout << ' ' << j;
}
bool TESTS = 0;
signed main(void)
{ io(); // file((char*)"input.in",(char*)"output2.out");
int tests = 1;
if( TESTS ) cin >> tests;
while( tests-- ) rewenie();
return 0;
}
컴파일 시 표준 에러 (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... |