제출 #1324570

#제출 시각아이디문제언어결과실행 시간메모리
1324570heyder_7Art Exhibition (JOI18_art)C++20
100 / 100
131 ms12096 KiB
#include <bits/stdc++.h>
#define int long long
using namespace std;
#define F first 
#define S second
#define pb push_back
#define ins insert
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define yes cout << "YES" << endl
#define no cout << "NO" << endl
#define srt(p) sort(p.begin() , p.end())
#define rvr(p) reverse(p.begin() , p.end())
#define all(p) (p.begin() , p.end())
const int INF = 1e6 , MOD = 1e9 + 7;

bool is_prime(int n) {
	if(n == 1 or n == 0) return false;
	if(n == 2) return true;
	if(n % 2 == 0) return false;
	for(int i = 3; i <= sqrt(n); i+=2) {
		if(n % i == 0) return false;
	}
	return true;
}

struct Edge {
    int u , v , w;
};

void solve() {
    int n;
    cin >> n;
    vector<pair<int , int>> vt(n);
    for(int i = 0; i < n; ++ i) {
        cin >> vt[i].F >> vt[i].S;
    }
    srt(vt);
    vector<int> dp(n + 10 , 0);
    dp[0] = vt[0].S;
    for(int i = 1; i < n; ++ i) {
        dp[i] = max((dp[i - 1] + vt[i].S - vt[i].F + vt[i - 1].F) , vt[i].S);
    }
    int maxi = INT_MIN;
    for(int i = 0; i < n; ++ i) {
        maxi = max(maxi , dp[i]);
    }
    cout << maxi << endl;
}

signed main() {
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin >> t;
    while (t--) {
        solve();
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...