GreatSolver's blog

By GreatSolver, history, 5 years ago, In English

Why is this code getting RTE? https://ideone.com/fork/KqmvTw The problem statememt: https://cses.fi/problemset/task/1092 Thanks in advance.

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

I think k — sum1 < 0 for some cases .

Simply do this .

n = 4

1 2 3 4

set1 : 1 4

set2 : 2 3

n = 6

1 2 3 4 5 6

The ans will be no because odd number of pairs .

n = 8

1 2 3 4 5 6 7 8

set1 : 1 8 3 6

set2 : 2 7 4 5

Property of arithmetic progression .

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

Try taking n as long long. Your code is having integer overflow when you take n >= 1e5

»
5 years ago, # |
  Vote: I like it +3 Vote: I do not like it

Thanks both so much