Submission #858766

# Submission time Handle Problem Language Result Execution time Memory
858766 2023-10-09T07:27:12 Z cig32 Hiring (IOI09_hiring) C++17
0 / 100
173 ms 19660 KB
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
const int MAXN = 3e5 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
  int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
int bm(int b, int p) {
  if(p==0) return 1 % MOD;
  int r = bm(b, p >> 1);
  if(p&1) return (((r*r) % MOD) * b) % MOD;
  return (r*r) % MOD;
}
int inv(int b) { 
  return bm(b, MOD-2);
}
int fastlog(int x) {
  return (x == 0 ? -1 : 64 - __builtin_clzll(x) - 1);
}
void printcase(int i) { cout << "Case #" << i << ": "; }
static void run_with_stack_size(void (*func)(void), size_t stsize) {
  char *stack, *send;
  stack = (char *)malloc(stsize);
  send = stack + stsize - 16;
  send = (char *)((uintptr_t)send / 16 * 16);
  asm volatile(
    "mov %%rsp, (%0)\n"
    "mov %0, %%rsp\n"
    :
    : "r"(send));
  func();
  asm volatile("mov (%0), %%rsp\n" : : "r"(send));
  free(stack);
}
bool cmp(pair<pair<int, int>, int> x, pair<pair<int, int>, int> y) {
  return x.first.first * y.first.second < y.first.first * x.first.second;
}
int bit[20202];
void add(int x, int v) {
  for(;x<20202;x+=x&-x)bit[x]+=v;
}
int sum(int x) {
  int s=0;
  for(;x;x-=x&-x)s+=bit[x];
  return s;
}
int bit2[20202];
void add2(int x, int v) {
  for(;x<20202;x+=x&-x)bit2[x]+=v;
}
int sum2(int x) {
  int s=0;
  for(;x;x-=x&-x)s+=bit2[x];
  return s;
}
void solve(int tc) {
  int n, w;
  cin >> n >> w;
  pair<pair<int, int>, int> a[n+1];
  for(int i=1; i<=n; i++) {
    cin >> a[i].first.first >> a[i].first.second;
    a[i].second = i;
  }
  sort(a+1, a+1+n, cmp);
  int ans1 = 0, ans2 = 1e18;
  int id = 0;
  for(int i=1; i<=n; i++) {
    int u = w * a[i].first.second / a[i].first.first;
    add(a[i].first.second, 1);
    add2(a[i].first.second, a[i].first.second);
    int lb = 0, rb = 20000;
    while(lb < rb) {
      int mid = (lb + rb + 1) >> 1;
      if(sum2(mid) <= u) lb = mid;
      else rb = mid - 1;
    }
    int cnt = sum(lb);
    int bruh = (u - sum2(lb)) / (lb + 1);
    bruh = min(bruh, sum(lb + 1) - sum(lb));
    cnt += bruh;
    int amt = sum2(lb) + bruh * (lb + 1);
    if(cnt > ans1) {
      id = i;
      ans1 = cnt;
      ans2 = amt;
    }
    else if(cnt == ans1 && amt < ans2) {
      id = i;
      ans2 = amt;
    }
  }
  cout << ans1 << '\n';
  if(ans1 == 0) return;
}
void uwu() {
  ios::sync_with_stdio(0); cin.tie(0);
  int t = 1; //cin >> t;
  for(int i=1; i<=t; i++) solve(i);
}
int32_t main() {
  #ifdef ONLINE_JUDGE
  uwu();
  #endif
  #ifndef ONLINE_JUDGE
  run_with_stack_size(uwu, 1024 * 1024 * 1024); // run with a 1 GiB stack
  #endif
}
/*
g++ C.cpp -std=c++17 -O2 -o C
./C < input.txt
*/

Compilation message

hiring.cpp: In function 'void solve(long long int)':
hiring.cpp:69:7: warning: variable 'id' set but not used [-Wunused-but-set-variable]
   69 |   int id = 0;
      |       ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
2 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
3 Incorrect 0 ms 348 KB Unexpected end of file - int32 expected
4 Incorrect 0 ms 504 KB Unexpected end of file - int32 expected
5 Incorrect 0 ms 344 KB Unexpected end of file - int32 expected
6 Incorrect 1 ms 860 KB Unexpected end of file - int32 expected
7 Incorrect 1 ms 508 KB Unexpected end of file - int32 expected
8 Incorrect 1 ms 600 KB Unexpected end of file - int32 expected
9 Incorrect 2 ms 860 KB Unexpected end of file - int32 expected
10 Incorrect 2 ms 860 KB Unexpected end of file - int32 expected
11 Incorrect 3 ms 916 KB Unexpected end of file - int32 expected
12 Incorrect 3 ms 2652 KB Unexpected end of file - int32 expected
13 Incorrect 4 ms 892 KB Unexpected end of file - int32 expected
14 Incorrect 5 ms 1116 KB Unexpected end of file - int32 expected
15 Incorrect 5 ms 1220 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 604 KB Unexpected end of file - int32 expected
2 Incorrect 1 ms 348 KB Unexpected end of file - int32 expected
3 Incorrect 0 ms 604 KB Unexpected end of file - int32 expected
4 Incorrect 8 ms 1488 KB Unexpected end of file - int32 expected
5 Incorrect 20 ms 3928 KB Unexpected end of file - int32 expected
6 Incorrect 106 ms 11344 KB Unexpected end of file - int32 expected
7 Incorrect 130 ms 15184 KB Unexpected end of file - int32 expected
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 44 ms 5088 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 70 ms 9040 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 156 ms 16464 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 173 ms 19660 KB Unexpected end of file - int32 expected
2 Halted 0 ms 0 KB -