Submission #1127458

#TimeUsernameProblemLanguageResultExecution timeMemory
1127458Haciyev12Art Exhibition (JOI18_art)C++20
0 / 100
1 ms320 KiB
#include "bits/stdc++.h" #define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); #define ll long long #define pb push_back #define in insert #define F first #define S second #define vll vector<ll> #define all(v) v.begin(),v.end() #define endl '\n' #define pii pair<ll,ll> using namespace std; const ll INF = 1e18, mod = 1e9 + 7, N = 2e5 + 5; ll gcd(ll a, ll b){ if(b == 0){ return a; } return gcd(b, a%b); } ll lcm(ll a, ll b){ return (a / gcd(a,b)) * b; } void solve(){ ll n,m; cin >> n; vector<pii>v; v.pb({0, 0}); ll a,b; for(int i = 0; i < n; i++){ cin >> a >> b; v.pb({a,b}); } vector<ll>pre(n + 1, 0); sort(all(v)); pre[1] = v[1].S; ll maxi = 0; ll mini = v[1].F, maximum = v[1].F; for(int i = 2; i <= n; i++){ mini= min(mini, v[i].F); maximum = max(maximum, v[i].F); pre[i] = pre[i - 1] + v[i].S; maxi = max(maxi, pre[i] - (maximum - mini)); } cout << maxi << endl; /*ll maxi = 0; for(int i = 1; i <= n; i++){ for(int j = i; j <= n; j++){ maxi = max(maxi, pre[j] - pre[i - 1] - (v[j].F - v[i].F)); } } cout << maxi << endl;*/ } int main() { fast; ll t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...