/1009/problem/C Annoying Present

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
#include<bits/stdc++.h>
using namespace std;
long long n,m;
long long ans=0;

long long f(long long d)
{/*
    int t;
    int flag=0;
    for(int k=1;k<=n;k++)
    {
        int x=0;
        for(int i=1; i<=n; i++)
        {
            x+=abs(k-i);
        }
        if(flag==0)
        {
            flag=1;
            t=x;
            continue;
        }
        if(d*x>d*t)t=x;
    }
    cout<<t*d<<endl;
    return t*d;*/
    if(d>0)
    {//cout<<d*n*(n-1)/2<<endl;
        return d*n*(n-1)/2;
    }
    else if(d==0)
    {//cout<<0<<endl;
        return 0;
    }
    else
    { bool e=n&1;
        //if(n%2==0)
        if(e==0)
        {
            //cout<<d*n*n/4<<endl;
            return d*n*n/4;
        }
        else
        {//cout<<d*(n+1)*(n-1)/4<<endl;
            return d*(n+1)*(n-1)/4;
        }
    }

}
int main()
{
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        long long x,d;
        cin>>x>>d;
        ans+=x*n;
        ans+=f(d);
    }
    double nn=n;
    printf("%.8f\n",ans/nn);
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值