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 ;
}

C. Annoying Present SB题的更多相关文章

  1. Codeforces 1009C: Annoying Present

    C. Annoying Present time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  2. 最小生成树(prim和Kruskal操!!SB题)

    Arctic Network Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 30571   Accepted: 9220 D ...

  3. 多项式乘法,sb题

    给定一个n,输出\((a1+x)*(a2+x)*...(an+x)\)的多项式长度. 每一个字符(包括"a"."x"."(".") ...

  4. 扔几道sb题

    1.给定一个长度为N的数列,A1, A2, ... AN,如果其中一段连续的子序列Ai, Ai+1, ... Aj(i <= j)之和是K的倍数,我们就称这个区间[i, j]是K倍区间. 你能求 ...

  5. nyoj744——异或(sb题)

    蚂蚁的难题(一) 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 小蚂蚁童鞋最近迷上了位运算,他感觉位运算非常神奇.不过他最近遇到了一个难题: 给定一个区间[a,b] ...

  6. Educational Codeforces Round 47 (Rated for Div. 2) :C. Annoying Present(等差求和)

    题目链接:http://codeforces.com/contest/1009/problem/C 解题心得: 题意就是一个初始全为0长度为n的数列,m此操作,每次给你两个数x.d,你需要在数列中选一 ...

  7. NOIPSB评测机+SB题DAY2

    忍者钩爪 题目描述 小 Q 是一名酷爱钩爪的忍者, 最喜欢飞檐走壁的感觉, 有一天小 Q 发现一个练习使用钩 爪的好地方,决定在这里大显身手. 场景的天花板可以被描述为一个无穷长的数轴, 初始小 Q ...

  8. 【Codeforces 1009C】Annoying Present

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 其实就是让你最后这n个数字的和最大. 加上的x没有关系.因为肯定都是加上n个x 所以直接加上就可以了 主要在于如何选取j 显然我们要找到一个位 ...

  9. Annoying Present

    http://codeforces.com/group/1EzrFFyOc0/contest/1009/problem/C 题意:原本有一个n个0的数组a[],你对它进行m次操作,每次操作让a[j]+ ...

随机推荐

  1. ListView学习

    ListView类 常用的基本属性 FullRowSelect:设置是否行选择模式.(默认为false)提示:只有在Details视图,该属性有效. GridLines:设置行和列之间是否显示网格线. ...

  2. gp的纯属意外的意外

    一不小心,把方法都传过去了,一脸蒙蔽说的就是我,啊哈哈哈啊哈

  3. Django笔记 —— 高级视图和URL配置

    最近在学习Django,打算玩玩网页后台方面的东西,因为一直很好奇但却没怎么接触过.Django对我来说是一个全新的内容,思路想来也是全新的,或许并不能写得很明白,所以大家就凑合着看吧- 本篇笔记(其 ...

  4. C++学习008-delete与delete[]的差别

    对于简单的数据类型,delete与delete[]是没啥差别的,就是等价的 例如 int main() { int *pdata = new int[20]; delete pdata; //dele ...

  5. 自动化测试学习之路--java 数组

    数组的定义与为数组元素分配空间和赋值是分开进行的,称为动态初始化. 在数组定义的同时就为数组元素分配空间并赋值,称为静态初始化. 一维数组举例: //动态初始化 int[] intArr; intAr ...

  6. Python 3基础教程22-单个列表操作

    本文来介绍列表的操作,先看看单个列表的操作,列表有多个方法.以下多行代码,建议你写一个方法,测试运行一个方法,不然看起来很乱. # 元组操作 x = [5,6,2,1,6,7,2,7,9] # app ...

  7. NOI中“大整数加法”问题不能AC的解决建议

    一.检查输入000和00相加是否出结果. 二.数组不要开小了,亲测256的数组不够.推荐1024.   附录AC程序: 如果不能AC请将256改为1024,255改为1023. #include &l ...

  8. CCF-NOIP-2018 提高组(复赛) 模拟试题(四)

    T1 贪吃蛇 [问题描述] 贪吃蛇是一个好玩的游戏.在本题中,你需要对这个游戏进行模拟. 这个游戏在一个 \(n\) 行 \(m\) 列的二维棋盘上进行. 我们用 \((x, y)\) 来表示第 \( ...

  9. Java并发基础--Thread类

    一.Thread类的构成 Thread类实现Runnable接口.部分源码如下: 二.Thread类常用方法 1.currentThread()方法 currentThread()方法可以返回代码段正 ...

  10. UVA 11297 Census(二维线段树)

    Description This year, there have been many problems with population calculations, since in some cit ...