Official

A - Balloon Trip Editorial by en_translator


For beginners

Original proposer: admin

What we want to find is the smallest integer \(n\) with \(1000W < nB\).
The possible approaches to find this include:

  • running a for loop.
  • Deform it to \(\displaystyle \frac{1000W}{B} < n\). This implies that the answer is \(\displaystyle \left \lfloor \frac{1000W}{B} \right \rfloor + 1\). (\(\lfloor x \rfloor\) is the value \(x\) but rounded down.)

Sample code 1 (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  int w,b;
  cin >> w >> b;
  for(int n=1;;n++){
    if(1000*w < n*b){cout << n << "\n"; break;}
  }
  return 0;
}

Sample code 2 (C++):

#include<bits/stdc++.h>

using namespace std;

int main(){
  int w,b;
  cin >> w >> b;
  cout << (1000*w/b)+1 << "\n";
  return 0;
}

posted:
last update: