Problem statement is here: http://acm.timus.ru/problem.aspx?space=1&num=1638
This is a tricky problem. First make sure you understand the example. Then try this example:
30 65 45 12 Solution: 5310
If you understand the above example and the one given in the problem statement, it is fairly easy to code.
public void solve(int testNumber, InputReader in, OutputWriter out) { int bookThickness = in.nextInt(); int coverThickness = in.nextInt(); int startVol = in.nextInt(); int endVol = in.nextInt(); int totalThickness = bookThickness + 2 * coverThickness; if (endVol > startVol) { out.println((endVol - startVol - 1) * totalThickness + 2 * coverThickness); } else if (startVol > endVol) { out.println((startVol - endVol - 1) * totalThickness + 2 * (bookThickness + coverThickness)); } else { out.println(bookThickness); } }