Submission #972297

#TimeUsernameProblemLanguageResultExecution timeMemory
972297vjudge1Art Exhibition (JOI18_art)C++17
10 / 100
13 ms468 KiB
#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)

art.cpp: In function 'void solve()':
art.cpp:52:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=0;j < v.sz;j++){
      |                       ^
art.cpp: At global scope:
art.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   67 | main() {
      | ^~~~
art.cpp: In function 'void freopen(std::string)':
art.cpp:26:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout);}
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
art.cpp:26:75: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   26 | void freopen(string s) { freopen((s + ".in").c_str(), "r", stdin); freopen((s + ".out").c_str(), "w", stdout);}
      |                                                                    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...