# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
958595 | KasymK | Art Exhibition (JOI18_art) | C++17 | 1064 ms | 600 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"
using namespace std;
#define int long long
int n;
int ans = -1e18;
vector<int> a, b, vis;
void barla(string s){
int S = 0;
int minA = 1e18, maxA = -1e18;
bool bamy = false;
for(char &i : s)
if(i == '1'){
bamy = true;
break;
}
if(!bamy)
return;
for(int i = 0; i < n; ++i)
if(s[i] == '1'){
S += b[i];
minA = min(minA, a[i]);
maxA = max(maxA, a[i]);
}
ans = max(ans, S - (maxA - minA));
}
void f(int x){
if(x == n){
// name ucin gecenok
string s;
for(int &i : vis)
s += (i ? '1' : '0');
barla(s);
return;
}
for(int i = 0; i <= 1; ++i){
vis[x] = i;
f(x + 1);
}
}
void solve(){
scanf("%lld", &n);
a.resize(n);
b.resize(n);
vis.resize(n);
for(int i = 0; i < n; ++i)
scanf("%lld %lld", &a[i], &b[i]);
f(0);
printf("%lld\n", ans);
}
signed main(){
int t = 1;
// scanf("%d", &t);
while(t--)
solve();
return 0;
}
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... |