QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747429 | #5481. Beast Bullies | rahulmnavneeth | WA | 56ms | 7032kb | C++17 | 4.2kb | 2024-11-14 17:09:29 | 2024-11-14 17:09:30 |
Judging History
answer
/*
File: icpc-mock-141124-A-a_main.cpp
Date and Time Created: 2024-11-14 14:33:26
Author: Rahul M. Navneeth
*/
/* ----------------- HEADER FILES ----------------- */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/* ----------------- NAMESPACE ----------------- */
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
/* ----------------- TEMPLATES ------------------ */
/* clang-format off */
// MACROS
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define io freopen("./input.txt", "r", stdin); freopen("./output.txt", "w", stdout); freopen("./output.txt", "w", stderr);
// TYPEDEF
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // POLICY BASED DS
// SHORTCUTS
#define ar array
#define pb push_back
#define pob pop_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define F first
#define S second
#define UNIQUE_SORT(v) sort(all(v)); v.erase(unique(all(v)), v.end())
// FUNCTIONS
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void swap(int &x, int &y) { int temp = x; x = y; y = temp; }
ll combination(ll n, ll r, ll m, ll *fact, ll *ifact) { ll val1 = fact[n]; ll val2 = ifact[n - r]; ll val3 = ifact[r]; return (((val1 * val2) % m) * val3) % m; }
bool revsort(ll a, ll b) {return a > b;}
ll phin(ll n) {ll number = n; if (n % 2 == 0) {number /= 2; while (n % 2 == 0) n /= 2;} for (ll i = 3; i <= sqrt(n); i += 2) {if (n % i == 0) {while (n % i == 0)n /= i; number = (number / i * (i - 1));}} if (n > 1)number = (number / n * (n - 1)) ; return number;} //O(sqrt(N))
ll getRandomNumber(ll l, ll r) {return uniform_int_distribution<ll>(l, r)(rng);}
vector<ll> sieve(int n) {int*arr = new int[n + 1](); vector<ll> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
ll modpow(ll a, ll b, ll MOD) { ll res = 1; while(b > 0) { if(b & 1) { res = (res * a) % MOD; } b = b >> 1; a = (a*a) % MOD; } return res; }
void extendgcd(ll a, ll b, ll *v) { if (b == 0) { v[0] = 1; v[1] = 0; v[2] = a; return; }
extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return; } // PASS AN ARRY OF SIZE1 3
ll mminv(ll a, ll b) { ll arr[3]; extendgcd(a, b, arr); return arr[0]; } // FOR NON PRIME B
ll mminvprime(ll a, ll b) { return modpow(a, b - 2, b); }
ll mod_add(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a + b) % m) + m) % m; }
ll mod_mul(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a * b) % m) + m) % m; }
ll mod_sub(ll a, ll b, ll m) { a = a % m; b = b % m; return (((a - b) % m) + m) % m; }
ll mod_div(ll a, ll b, ll m) { a = a % m; b = b % m; return (mod_mul(a, mminvprime(b, m), m) + m) % m; } // ONLY FOR PRIME M
void precision(int a) { cout << setprecision(a) << fixed; }
// CONSTANTS
const float PI = 3.141592653589793238462;
const int MOD = 1e9 + 7;
const int mxn = 1e7;
const int LOG = 30;
/* --------------------- CODE BEGINS ---------------------- */
void solve() {
ll N; cin >> N;
vector<ll> a(N); for(ll i = 0 ; i < N; i++) cin >> a[i];
sort(all(a)); reverse(all(a));
ll x = 0;
ll i = 0;
ll c = 0;
while(i < N) {
ll y = a[i];
while(i + 1 < N && y < x) {
i++;
y += a[i];
}
if(y >= x) {
c = i;
x = y;
}
i++;
}
cout << c+1 << "\n";
return;
}
/*---------------------- MAIN DRIVER ------------------------*/
// MAIN
int32_t main() {
fast_io
#ifndef ONLINE_JUDGE
io;
#endif
high_resolution_clock::time_point start, end;
#ifndef ONLINE_JUDGE
start = chrono::high_resolution_clock::now();
#endif
int t = 1;
int i = 1;
// cin >> t;
while (i <= t) {
#ifndef ONLINE_JUDGE
cout << "TESTCASE #" << i << "\n";
#endif
i++;
solve();
}
#ifndef ONLINE_JUDGE
end = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::milliseconds>(end - start);
cout << "-------------\nRUNTIME: " << duration.count() << " ms\n";
#endif
return 0;
}
/* clang-format on */
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 56ms
memory: 7032kb
input:
500000 976631732 51389671 729809897 630844317 294721017 903231515 477913449 871071076 636104080 345822085 97441187 499323378 522845426 310022664 199310190 776622973 602672555 646874222 214723272 285341530 962727359 681361226 47426538 272153520 693133904 542337627 556307610 325596239 95738088 5495543...
output:
485711
result:
wrong answer 1st lines differ - expected: '155101', found: '485711'