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>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pii pair<int,int>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define f first
#define int double
#define s second
#define pii pair<int,int>
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
tree_order_statistics_node_update> ordered_set;
const int N=3e5 + 5 ;
const int inf = 1e17 + 7;
const int mod = 998244353;
long long binpow(long long n, long long m){
if(m == 0)return 1;
else if(m % 2 == 0){
long long sum = binpow(n,m/2);
return sum * sum;
}
else{
return binpow(n,m-1)*n;
}
}
void solve(){
int n,m,k;
cin>>n;
vector<array<int,2>>v(n);
for(int i = 0;i<n;i++){
int a,b;
cin>>a>>b;
v[i][0] = a;
v[i][1] = b;
}
int ans = 0;
for(long long mask = 0;mask < binpow(4,n);mask+=1){
int sum1 = 0, sum2 = 0;
int cnt = 0;
for(int i = 0;i<n;i++){
if(((mask/binpow(4,i))%4)==1){
cnt += 1;
sum1 +=v[i][0];
}
if(((mask/binpow(4,i))%4)==2){
cnt += 1;
sum2 +=v[i][1];
}
if(((mask/binpow(4,i))%4)==3){
cnt += 1;
sum1 +=v[i][0];
cnt += 1;
sum2 += v[i][1];
}
}
umax(ans,min(sum2-cnt,sum1-cnt));
}
printf("%.4lf",(double)ans);
}
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin>>tt>>n;
while(tt--)solve();
}
Compilation message (stderr)
sure.cpp: In function 'void solve()':
sure.cpp:37:8: warning: unused variable 'm' [-Wunused-variable]
37 | int n,m,k;
| ^
sure.cpp:37:10: warning: unused variable 'k' [-Wunused-variable]
37 | int n,m,k;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |