Advertisement
Guest User

Untitled

a guest
May 22nd, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. import java.math.BigInteger;
  2. import java.util.Scanner;
  3.  
  4. public class B390 {
  5. public static void main(String[] args) {
  6. BigInteger happiness = BigInteger.valueOf(0);
  7. Scanner sc = new Scanner(System.in);
  8. int n = sc.nextInt();
  9. int[] a = new int[n];
  10. int[] b = new int[n];
  11. for (int i = 0; i < 2; i++) {
  12. for (int j = 0; j < n; j++) {
  13. if (i == 0) {
  14. a[j] = sc.nextInt();
  15. } else {
  16. b[j] = sc.nextInt();
  17. }
  18. }
  19. }
  20. BigInteger x;
  21. BigInteger y;
  22. for (int i = 0; i < n; i++) {
  23. if (b[i] == 1) {
  24. happiness = happiness.subtract(BigInteger.valueOf(1));
  25. }
  26. if (a[i] * 2 < b[i]) {
  27. happiness = happiness.subtract(BigInteger.valueOf(1));
  28. } else {
  29. if (b[i] % 2 == 0) {
  30. x = BigInteger.valueOf(b[i] / 2);
  31. happiness = happiness.add(x.multiply(x));
  32. } else {
  33. x = BigInteger.valueOf((b[i] - 1) / 2);
  34. y = BigInteger.valueOf((b[i] + 1) / 2);
  35. happiness = happiness.add(x.multiply(y));
  36. }
  37. }
  38. }
  39. System.out.println(happiness);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement