Submission #1287712

#TimeUsernameProblemLanguageResultExecution timeMemory
1287712herominhsteveArt Exhibition (JOI18_art)C++20
100 / 100
161 ms8340 KiB
#include <bits/stdc++.h>
#define el '\n'
#define FNAME "JOI18_art"
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,n) memset(x,(n),sizeof(x))
using namespace std;
const long long MOD = (long long) 1e9 + 7;
template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;}
template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;}

void setup(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	if (fopen(FNAME".inp","r")){
		freopen(FNAME".inp","r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

int n;
vector<pair<long long,long long>> pic;

void init(){
	cin>>n;
	pic.resize(n);
	for (pair<long long,long long> &x : pic) cin>>x.first>>x.second;
	sort(allof(pic));
}

void sol(){
	long long res=0,low=0,sum=0;
	for (const pair<long long,long long> &x : pic){
		minimize(low,sum - x.first);
		sum += x.second;
		maximize(res,sum - x.first - low);
	}
	cout<<res;
}

int main(){
    setup();
    init();
    sol();
}

Compilation message (stderr)

art.cpp: In function 'void setup()':
art.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |                 freopen(FNAME".inp","r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
art.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 freopen(FNAME".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...