# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
471093 | robell | Art Exhibition (JOI18_art) | C++17 | 1069 ms | 9068 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define mod 1e9+7
void setIO(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
}
void setIO(string f){
freopen((f+".in").c_str(),"r",stdin);
freopen((f+".out").c_str(),"w",stdout);
setIO();
}
pair<ll,ll> v[500000];
int N;
ll check(ll D){
int l=0;
int r=0;
ll col = 0;
ll maxv = -1e18;
while (l<N){
if (r!=N){
if (v[r].first-v[l].first<=D){
col+=v[r].second;
r++;
}else{
maxv=max(col-(v[r-1].first-v[l].first),maxv);
l++;
col-=v[l].second;
}
}else{
maxv=max(col-(v[r-1].first-v[l].first),maxv);
l++;
col-=v[l].second;
}
}
return maxv;
}
int main(){
setIO();
cin >> N;
for (int i=0;i<N;i++){
cin >> v[i].first >> v[i].second;
}
sort(v,v+N);
// ll maxD = v[N-1].first-v[0].first;
// ll minD = 0;
// while (minD!=maxD){
// ll mid = (maxD+minD+1)/2;
// if (check(mid)>=check(mid+1)){
// minD=mid;
// }else{
// maxD=mid-1;
// }
// }
// cout << check(minD) << " " << minD << "\n";
ll maxv = -1e18;
for (int i=0;i<N;i++){
ll col = 0;
for (int j=i;j<N;j++){
col+=v[j].second;
maxv=max(maxv,col-(v[j].first-v[i].first));
}
}
cout << maxv << "\n";
}
Compilation message (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... |