Submission #1127511

#TimeUsernameProblemLanguageResultExecution timeMemory
1127511anuarArt Exhibition (JOI18_art)C++20
0 / 100
0 ms320 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;
}

Compilation message (stderr)

art.cpp: In function 'void file(const char*, const char*)':
art.cpp:13:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |       freopen(in, "r", stdin);
      |       ~~~~~~~^~~~~~~~~~~~~~~~
art.cpp:14:14: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |       freopen(out, "w", stdout);
      |       ~~~~~~~^~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...