Submission #471100

# Submission time Handle Problem Language Result Execution time Memory
471100 2021-09-07T05:48:59 Z robell Art Exhibition (JOI18_art) C++14
0 / 100
0 ms 204 KB
#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;
int main(){
	setIO();
	cin >> N;
	for (int i=0;i<N;i++){
		cin >> v[i].first >> v[i].second;
	}
	sort(v,v+N);
	int l=0,r=0;
	ll prevM = -1e18;
	ll col = 0;
	ll totval = -1e18;
	while ((l<N)){
		if (r<N){
			if (col+v[r].second-(v[r].first-v[l].first)>prevM){
				prevM=col+v[r].second-(v[r].first-v[l].first);
				totval=max(totval,prevM);
				col+=v[r].second;
				r++;
			}else{
				col-=v[l].second;
				l++;
				prevM=-1e18;
			}
		}else{
			totval=max(totval,col-(v[r-1].first-v[l].first));
			col-=v[l].second;
			l++;
		}
	}
	cout << totval << "\n";
}

Compilation message

art.cpp: In function 'void setIO(std::string)':
art.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:20:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -