Created
July 14, 2018 15:55
-
-
Save chermehdi/5b7c8f2afe49876e66d9bfd9dec1f187 to your computer and use it in GitHub Desktop.
Main
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.mehdi.main.codeforces.edu_47; | |
import com.mehdi.lib.io.InputReader; | |
import java.io.PrintWriter; | |
import static com.mehdi.lib.Factories.*; | |
public class TaskC { | |
public void solve(int testNumber, InputReader in, PrintWriter out) { | |
int n = in.nextInt(); | |
int q = in.nextInt(); | |
double all = 0; | |
for (int i = 0; i < q; i++) { | |
double x = in.nextInt(); | |
double d = in.nextInt(); | |
double max = x * n + d * ((n - 1) * (double)(n) / 2.0); | |
double min = 0; | |
double size = n / 2; | |
min = x + 2.0 * (x * size + d * extractSum(size)); | |
if (n % 2 == 0) { | |
min -= d * size; | |
} | |
all += Math.max(min, max); | |
} | |
out.printf("%.8f", all / (double) n); | |
} | |
private double extractSum(double n) { | |
if(n == 1.0) return 1; | |
return (n - 1) * (n) / 2.0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment