# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
972297 | vjudge1 | Art Exhibition (JOI18_art) | C++17 | 13 ms | 468 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define F first
#define S second
#define clr clear()
#define sz size()
#define str string
#define pf push_front
#define endl "\n"
#define M 5005
#define N 200005
#define set(a) fixed << setprecision(a)
#define all(s) s.begin(),s.end()
#define ppb pop_back()
#define ppf pop_front()
#define ios_base ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int T = 1;
const int inf = 1e18+7;
void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout);}
int lcm(int a,int b){return (a / __gcd(a, b)) * b;};
int binpow(int a,int n){if(n==0)return 1;else if(n%2==1)return binpow(a,n-1)*a;else{int b = binpow(a,n/2);return b*b;}}
int nceil(int a,int b){return (a+b-1)/b;};
bool isbig(char x){return x >= 65 && x <= 90;}
bool issmall(char x){return x >= 97 && x <= 122;}
struct edge{
int a,b;
} p[N];
void solve(){
int n;
cin >> n;
for(int i=0;i < n;i++){
cin >> p[i].a >> p[i].b;
}
int maxx = -inf;
for(int i=1;i < (1 << n);i++){
vector <edge> v;
for(int j=0;j < n;j++){
if(i & (1 << j)){
// cout << "j = " << j << " ";
v.pb(p[j]);
}
}
int sum = 0,mn = inf,mx = 0;
for(int j=0;j < v.sz;j++){
mx = max(mx,v[j].a);
sum+=v[j].b;
mn = min(mn,v[j].a);
// if(i==5){
// cout << endl;
// cout << v[j].a << " " << v[j].b;
// }
}
maxx = max(sum-mx+mn,maxx);
// cout << "i = " << i << " maxx = " << maxx << " sum = " << sum << " mn = " << mn << " mx = " << mx << endl;
}
cout << maxx;
}
main() {
ios_base;
// cin >> T;//ne zabyd steret
// freopen("");
while(T--){
solve();
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |