Submission #1694456


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
ll a[111];
bool used[111];

int main(){
	cin>>n;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  ll res=INF;
  rep(i,n)rep(j,i){
    ll mina=a[i]+a[j];
    set<P> st;
    memset(used,0,sizeof(used));
    used[i]=used[j]=true;
    rep(k,n){
      if(used[k])continue;
      st.insert(P(a[k],k));
    }
    ll maxa=-1;
    bool ok=true;
    for(ll k=n-1;k>=0;k--){
      if(used[k])continue;
      st.erase(P(a[k],k));
      auto c=st.lower_bound(P(mina-a[k],-1));
      if(c==st.end()){
        ok=false;
        break;
      }
      maxch(maxa,a[k]+(*c).fi);
      used[k]=used[(*c).se]=true;
      st.erase(c);
      //dbg(k); dbg((*c).se);
    }
    if(!ok)continue;
    minch(res,maxa-mina);
  }
  cout<<res<<endl;
	return 0;
}

Submission Info

Submission Time
Task A - Table Tennis
User yamad
Language C++14 (GCC 5.4.1)
Score 100
Code Size 1424 Byte
Status AC
Exec Time 43 ms
Memory 256 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 27
Set Name Test Cases
All 00-sample-00.txt, 00-sample-01.txt, 10-unique-00.txt, 10-unique-01.txt, 10-unique-02.txt, 10-unique-03.txt, 10-unique-04.txt, 20-order-00.txt, 20-order-01.txt, 20-order-02.txt, 20-order-03.txt, 20-order-04.txt, 30-random-00.txt, 30-random-01.txt, 30-random-02.txt, 30-random-03.txt, 30-random-04.txt, 30-random-05.txt, 30-random-06.txt, 30-random-07.txt, 30-random-08.txt, 30-random-09.txt, 30-random-10.txt, 30-random-11.txt, 30-random-12.txt, 30-random-13.txt, 30-random-14.txt
Case Name Status Exec Time Memory
00-sample-00.txt AC 1 ms 256 KB
00-sample-01.txt AC 1 ms 256 KB
10-unique-00.txt AC 1 ms 256 KB
10-unique-01.txt AC 41 ms 256 KB
10-unique-02.txt AC 15 ms 256 KB
10-unique-03.txt AC 28 ms 256 KB
10-unique-04.txt AC 1 ms 256 KB
20-order-00.txt AC 1 ms 256 KB
20-order-01.txt AC 43 ms 256 KB
20-order-02.txt AC 1 ms 256 KB
20-order-03.txt AC 24 ms 256 KB
20-order-04.txt AC 3 ms 256 KB
30-random-00.txt AC 1 ms 256 KB
30-random-01.txt AC 43 ms 256 KB
30-random-02.txt AC 1 ms 256 KB
30-random-03.txt AC 19 ms 256 KB
30-random-04.txt AC 15 ms 256 KB
30-random-05.txt AC 15 ms 256 KB
30-random-06.txt AC 16 ms 256 KB
30-random-07.txt AC 6 ms 256 KB
30-random-08.txt AC 3 ms 256 KB
30-random-09.txt AC 2 ms 256 KB
30-random-10.txt AC 4 ms 256 KB
30-random-11.txt AC 7 ms 256 KB
30-random-12.txt AC 6 ms 256 KB
30-random-13.txt AC 40 ms 256 KB
30-random-14.txt AC 1 ms 256 KB