제출 #1274115

#제출 시각아이디문제언어결과실행 시간메모리
1274115almazArt Exhibition (JOI18_art)C++20
10 / 100
7 ms580 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
// #define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ar array

const int MOD = 1e9 + 7,INF = 1e18, N = 2e5 + 5;
/*
*/

void solve(){
	int n;
	cin >> n;
	
	vector <int> a(n) , b(n);
	
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i];
	}
	
	int ans = 0;
	
	for(int i = 1;i < (1 << n);i++){
		int mx = 0, mn = INF, sum = 0;
		for(int j = 0;j < n;j++){
			if(1 & (i >> j)){
				mn = min(mn , a[j]);
				mx = max(mx , a[j]);
				sum += b[j];
			}
		}
		ans = max(ans , sum - (mx - mn));
	}
	cout<<ans<<endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int ti = 1;
    while (ti--) {
		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...