Submission #1156770


Source Code Expand

#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<deque>

using namespace std;

#define sz(x) (int)(x.size())
#define fi(a, b) for(int i=a;i<b;++i)
#define fj(a, b) for(int j=a;j<b;++j)
#define fk(a, b) for(int k=a;k<b;++k)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//////////

bool can(pii p, vector<pii> &a){
	int cnt = 0;
	ll me = p.first;
	fi(0, sz(a)){
		if(a[i] == p) continue;
		if(a[i].first <= me * 2){
			me += a[i].first;
		}else{
			return false;
		}
	}
	return true;
}

void solve(){
	int n;
	scanf("%d",&n);
	vector<pii> a;
	fi(0, n){
		int v;
		scanf("%d",&v);
		a.pb(mp(v, i));
	}
	sort(a.begin(), a.end());
	int l = -1;
	int r = n;
	while(r-l>1){
		int m = (l+r)/2;
		if(can(a[m], a)){
			r = m;
		}else{
			l = m;
		}
	}
	printf("%d\n",n-1-r+1);
}


int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();


	return 0;
}

Submission Info

Submission Time
Task B - Colorful Creatures
User Filyan
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1101 Byte
Status AC
Exec Time 22 ms
Memory 1400 KB

Compile Error

./Main.cpp: In function ‘void solve()’:
./Main.cpp:39:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
./Main.cpp:43:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&v);
                 ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 22 ms 1400 KB
in10.txt AC 9 ms 892 KB
in11.txt AC 21 ms 1400 KB
in12.txt AC 20 ms 1400 KB
in13.txt AC 21 ms 1400 KB
in2.txt AC 22 ms 1400 KB
in3.txt AC 22 ms 1400 KB
in4.txt AC 22 ms 1400 KB
in5.txt AC 9 ms 892 KB
in6.txt AC 21 ms 1400 KB
in7.txt AC 21 ms 1400 KB
in8.txt AC 21 ms 1400 KB
in9.txt AC 4 ms 512 KB
sample1.txt AC 1 ms 256 KB
sample2.txt AC 1 ms 256 KB
sample3.txt AC 1 ms 256 KB