【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

其实就是让你最后这n个数字的和最大。
加上的x没有关系。因为肯定都是加上n个x
所以直接加上就可以了
主要在于如何选取j
显然我们要找到一个位置j.
然后pre[j]+aft[j]的值最大(pre[j]=1+2+3+...+j-1,aft类似
(这是在d大于0的时候,小于0的时候找pre[j]+aft[j]最小的就好)

【代码】

#include <bits/stdc++.h>
#define ll long long
using namespace std; const int N = 1e5; int n,m;
ll x[N+10],d[N+10];
ll pre[N+10],aft[N+10];
ll ma,maidx = 1,mi,miidx = 1;
double ans = 0; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= m;i++) cin >> x[i] >> d[i];
for (int i = 1;i <= n;i++){
pre[i] = pre[i-1]+i-1;
}
for (int i = n;i >= 1;i--){
aft[i] = aft[i+1] + (n-i);
}
ma = pre[1]+aft[1];
for (int i = 2;i <= n;i++){
ll temp = pre[i]+aft[i];
if (temp>ma){
ma = temp;
maidx = i;
}
} mi = pre[1]+aft[1];
for (int i = 2;i <= n;i++){
ll temp = pre[i]+aft[i];
if (temp<mi){
mi = temp;
miidx = i;
}
} for (int i = 1;i <= m;i++){
ans = ans + n*x[i];
if (d[i]<0){
ans = ans + mi*d[i];
}else{
ans = ans + ma*d[i];
}
}
ans = 1.0*ans / n;
cout<<fixed<<setprecision(10)<<ans<<endl;
return 0;
}

【Codeforces 1009C】Annoying Present的更多相关文章

  1. Codeforces 1009C: Annoying Present

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

  2. 【Codeforces 4D】Mysterious Present

    [链接] 我是链接,点我呀:) [题意] 要求长度和宽度都严格递增(选择一个序列) 然后你一开始有一个长度和宽度 要求这个一开始所给的长度和宽度能接在你选择的一段连续的长度宽度的开头 (且保持原来的性 ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【39.66%】【codeforces 740C】Alyona and mex

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  5. 【codeforces 758A】Holiday Of Equality

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  6. 【13.91%】【codeforces 593D】Happy Tree Party

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  7. 【26.67%】【codeforces 596C】Wilbur and Points

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 764B】Timofey and cubes

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. 【codeforces 766C】Mahmoud and a Message

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

随机推荐

  1. 30. extjs getEl方法 怎么用

    转自:https://blog.csdn.net/evilcry2012/article/details/50586861 2014-10-27 11:57 提问者采纳   getEl = compo ...

  2. 《Effective C++》笔记:III(转载)

    转自:http://www.cnblogs.com/destino74/p/3960802.html 条款5:Know what functions C++ silently writes and c ...

  3. Python基础 — Pandas

    Pandas -- 简介 Python Data Analysis Library 或 pandas 是基于NumPy 的一种工具,该工具是为了解决数据分析任务而创建的.        Pandas ...

  4. 洛谷 P1414 又是毕业季II(未完成)

    题目背景 “叮铃铃铃”,随着高考最后一科结考铃声的敲响,三年青春时光顿时凝固于此刻.毕业的欣喜怎敌那离别的不舍,憧憬着未来仍毋忘逝去的歌.1000多个日夜的欢笑和泪水,全凝聚在毕业晚会上,相信,这一定 ...

  5. 牛客练习赛17-A-长方体

    题目描述 给出共享长方体一个顶点的三个面的面积,求它十二条边的边长和. 输入描述: 一行三个整数a, b, c表示面积(1 <= a, b, c <= 10000). 输出描述: 一行一个 ...

  6. uiautomatorviewer详解

    一,uiautomatorviewer是什么? Android 4.1发布的,uiautomator是用来做UI测试的.也就是普通的手工测试,点击每个控件元素 看看输出的结果是否符合预期.比如 登陆界 ...

  7. 每天学点Linux命令: 管道| 与 xargs的区别

    先看一个例子: find ./ -print | xargs grep a 输出: grep: ./: 是一个目录 ./less:abc ./afile:abcde ./afile:AaAbBcB . ...

  8. 274 H-Index H指数

    给定一位研究者的论文被引用次数的数组(被引用次数是非负整数).写一个方法计算出研究者的H指数.H-index定义: “一位科学家有指数 h 是指他(她)的 N 篇论文中至多有 h 篇论文,分别被引用了 ...

  9. SQL Split函数,将一串字符串返回成table

    写法一: CREATE FUNCTION [dbo].[Split] ( @str VARCHAR(MAX), --传进来的字符串 ) --分割符 ) RETURNS @t TABLE --定义一个虚 ...

  10. [ TJOI 2012 ] 防御

    \(\\\) Description 有 \(n\) 人,第 \(i\) 个人有一个护甲值 \(a_i\). 有 \(m\) 次操作,分为以下两种: \(A\ l\ r\ x\) 对编号在 \([l, ...