Frenzy_Love's blog

By Frenzy_Love, history, 10 months ago, In English

/* for l = 8, r = 26 */

include

include

include

include

using namespace std; using L = long; using LL = long long;

int main() {

int t;
cin >> t;

while (t--) {

    LL l, r;
    cin >> l >> r;

     LL res = (r >= 2 * l) ? (r - 1) / 2 : (r - l);

    cout << res << endl;
 }

return 0;

} /* how it is so that the answer is not 18 but 12!??? thanks, */

  • Vote: I like it
  • -14
  • Vote: I do not like it

»
10 months ago, # |
  Vote: I like it +3 Vote: I do not like it

you were wrong, you wrote that in the true case (r — 1), the place is (r — l), that's why you get 12

  • »
    »
    10 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    so if the machine compiles and executes the code, the answer is 12 which is correct and accepted, BUT, if I would be to do it with my own brain, I get 18, check this out: "LL res = (26 >= 2 * 8) ? (26-1)/2 : (26-8);" this is what my brain computes: is 26 bigger or equal than 16 ? if it's true: 12 for false: 18; it went accepted like this...should I stop doing push_ups while programming cause my eye bulges are popping red and I make the machine see floats ?

»
10 months ago, # |
  Vote: I like it 0 Vote: I do not like it

It should be long long res = (r>=2*l)? (r-l) : (r-1)/2;