C. Annoying Present
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Alice got an array of length nn as a birthday present once again! This is the third year in a row!

And what is more disappointing, it is overwhelmengly boring, filled entirely with zeros. Bob decided to apply some changes to the array to cheer up Alice.

Bob has chosen mm changes of the following form. For some integer numbers xx and dd, he chooses an arbitrary position ii (1≤i≤n1≤i≤n) and for every j∈[1,n]j∈[1,n] adds x+d⋅dist(i,j)x+d⋅dist(i,j) to the value of the jj-th cell. dist(i,j)dist(i,j) is the distance between positions ii and jj (i.e. dist(i,j)=|i−j|dist(i,j)=|i−j|, where |x||x| is an absolute value of xx).

For example, if Alice currently has an array [2,1,2,2][2,1,2,2] and Bob chooses position 33 for x=−1x=−1 and d=2d=2 then the array will become [2−1+2⋅2, 1−1+2⋅1, 2−1+2⋅0, 2−1+2⋅1][2−1+2⋅2, 1−1+2⋅1, 2−1+2⋅0, 2−1+2⋅1] = [5,2,1,3][5,2,1,3]. Note that Bob can't choose position ii outside of the array (that is, smaller than 11 or greater than nn).

Alice will be the happiest when the elements of the array are as big as possible. Bob claimed that the arithmetic mean value of the elements will work fine as a metric.

What is the maximum arithmetic mean value Bob can achieve?

Input

The first line contains two integers nn and mm (1≤n,m≤1051≤n,m≤105) — the number of elements of the array and the number of changes.

Each of the next mm lines contains two integers xixi and didi (−103≤xi,di≤103−103≤xi,di≤103) — the parameters for the ii-th change.

Output

Print the maximal average arithmetic mean of the elements Bob can achieve.

Your answer is considered correct if its absolute or relative error doesn't exceed 10−610−6.

Examples
input

Copy
2 3
-1 3
0 0
-1 -4
output

Copy
-2.500000000000000
input

Copy
3 2
0 2
5 0
output

Copy
7.000000000000000

  这题分析一下题目  就是对d的正负进行分类讨论 
  d>=0 则选择 i=1; 反之 i=(n+1)/2;
  代码量也特别少   
 #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + ;
const int INF = 0x3fffffff;
typedef long long LL;
using namespace std;
LL n, m, x, d, ans = ;
int main() {
scanf("%lld%lld", &n, &m);
for (int i = ; i < m ; i++) {
scanf("%lld%lld", &x, &d);
if (d >= ) ans += n * x + d * (n - ) * n / ;
else ans += n * x + d * (n - (n + ) / ) * ((n + ) / );
}
printf("%.8f\n", 1.0 * ans / n);
return ;
}

最新文章

  1. jquery实现多级下拉菜单
  2. VMware10 安装centos6.7 设置NAT模式
  3. 详解MySQL的用户密码过期功能
  4. C++模板中的函数对象
  5. SSRS集成至Web
  6. C#基于AE组件二次开发常见问题
  7. unity中的mesh合并
  8. C#代码设置窗体和Panel的位置大小
  9. Eclipse RCP /Plugin移除Search对话框
  10. angularjs ng-class
  11. TextMesh Pro Emoji Align With Text(表情和文字对齐)
  12. 为clang添加中文关键字
  13. V-bind详细使用
  14. jeecg入门操作—表单界面
  15. Hibernate入门(十)inverse
  16. 【CF809E】Surprise me! 树形DP 虚树 数学
  17. 【redis】redis配置文件参数解析
  18. java -version 版本号与path中配置的不一致
  19. SQL-结构化查询语言(2)
  20. js原生实现 无缝滚动图片

热门文章

  1. EXKMP学习笔记QAQ
  2. java 解析xml 多命名空间问题
  3. responsive grid
  4. Git的升级版本
  5. OrCAD设置原理图页面大小
  6. laravel5.5jwt-auth的使用
  7. 从浏览器或者Webview 中唤醒APP
  8. OSI七层模型加协议
  9. 玩转Vim-札记(一)
  10. ABP框架插件开发