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

【题意】

题意

【题解】

其实就是让你最后这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. J20180116

    用度 总务 用度係 总务科(管理办公用品等) 型紙 设计图 プラント 工厂

  3. 洛谷 P1045 麦森数

    题目描述 形如2^{P}-1的素数称为麦森数,这时P一定也是个素数.但反过来不一定,即如果P是个素数,2^{P}-1不一定也是素数.到1998年底,人们已找到了37个麦森数.最大的一个是P=30213 ...

  4. CF379F New Year Tree

    题意翻译 你是一个程序猿,现在有一棵新年树(并不是传统的带着叶子的树)--它有四个节点: 1,2,3,4. 其中2,3,4的父亲都是1. 新年里,程序猿们往往会做一些有趣的事情.你则选择以往这棵树上加 ...

  5. bash、dash(/bin/bash和/bin/sh)的区别

    Linux中的shell有多种类型,其中最常用的几种是Bourne   shell(sh).C   shell(csh)和Korn   shell(ksh).三种shell各有优缺点. Bourne ...

  6. node-rsa加密,java解密调试

    用NODE RSA JS 加密解密正常,用JAVA RSAUtils工具类加密解密正常.但是用node加密玩的java解密不了.原因:node默认的是 DEFAULT_ENCRYPTION_SCHEM ...

  7. leetcode486 Predict the Winner

    思路: 博弈. 实现: class Solution { public: bool PredictTheWinner(vector<int>& nums) { ][]; int n ...

  8. Selenium基于Python web自动化基础二 -- 免登录、等待及unittest单元测试框架

    一.免登录在进行测试的过程中难免会遇到登录的情况,给测试工作添加了工作量,本文仅提供一些思路供参考解决方式:手动请求中添加cookies.火狐的profile文件记录信息实现.人工介入.万能验证码.去 ...

  9. Eclipse 编译java文件后出错 左树无红叉

    问题描述: 今天遇见让人郁闷的问题,在项目工程中java文件编译通不过,eclipse在java文件中标示错误,但是却不不能在navigator的视图中像平常一样出现小红叉.通过clean proje ...

  10. glic,uClibc,EGLIBC 简要介绍

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...