cf 1016C
2 seconds
256 megabytes
standard input
standard output
Vasya's house is situated in a forest, and there is a mushroom glade near it. The glade consists of two rows, each of which can be divided into n consecutive cells. For each cell Vasya knows how fast the mushrooms grow in this cell (more formally, how many grams of mushrooms grow in this cell each minute). Vasya spends exactly one minute to move to some adjacent cell. Vasya cannot leave the glade. Two cells are considered adjacent if they share a common side. When Vasya enters some cell, he instantly collects all the mushrooms growing there.
Vasya begins his journey in the left upper cell. Every minute Vasya must move to some adjacent cell, he cannot wait for the mushrooms to grow. He wants to visit all the cells exactly once and maximize the total weight of the collected mushrooms. Initially, all mushrooms have a weight of 0. Note that Vasya doesn't need to return to the starting cell.
Help Vasya! Calculate the maximum total weight of mushrooms he can collect.
The first line contains the number n (1 ≤ n ≤ 3·105) — the length of the glade.
The second line contains n numbers a1, a2, ..., an (1 ≤ ai ≤ 106) — the growth rate of mushrooms in the first row of the glade.
The third line contains n numbers b1, b2, ..., bn (1 ≤ bi ≤ 106) is the growth rate of mushrooms in the second row of the glade.
Output one number — the maximum total weight of mushrooms that Vasya can collect by choosing the optimal route. Pay attention that Vasya must visit every cell of the glade exactly once.
3
1 2 3
6 5 4
70
3
1 1000 10000
10 100 100000
543210
In the first test case, the optimal route is as follows:
Thus, the collected weight of mushrooms will be 0·1 + 1·2 + 2·3 + 3·4 + 4·5 + 5·6 = 70.
In the second test case, the optimal route is as follows:
Thus, the collected weight of mushrooms will be 0·1 + 1·10 + 2·100 + 3·1000 + 4·10000 + 5·100000 = 543210.
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;
typedef long long ll;
int n;
#define N 300009
#define ll long long
ll a[][N],sum[][N],s[N];
/*
sum[0][i]:从a[0][i]走到a[1][i]的花费,a[0][i]为起点,a[1][i]为终点
sum[0][i]:从a[1][i]走到a[0][i]的花费,a[1][i]为起点,a[0][i]为终点
s[i] : 前i列的两行数据之和
*/
int main()
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%lld",&a[][i]);
for(int i=;i<=n;i++) scanf("%lld",&a[][i]);
for(int i=;i<=n;i++) s[i]=s[i-]+a[][i]+a[][i];
sum[][n]=a[][n];sum[][n]=a[][n];
for(int i=n-;i>=;i--){
sum[][i]=sum[][i+]+s[n]-s[i]+a[][i]*(+*(n-i));
/*
s[n]-s[i]+a[1][i]*(1+2*(n-i)):sum[0][i]与sum[1][i]的差值
*/
sum[][i]=sum[][i+]+s[n]-s[i]+a[][i]*(+*(n-i));
}
ll ans=sum[][];
ll cnt=;
//只能前面若干个锯齿行走,在U 行走
for(int i=;i<=n;i++){
if(i&){
cnt+=a[][i]*(*i-)+a[][i]*(*i-);//锯齿花费
ans=max(ans,cnt+sum[][i+]+(s[n]-s[i])*(*i));
//(s[n]-s[i])*(2*i) :sum[1][i+1]的起点为i+1,但实际不是
}
else{
cnt+=a[][i]*(*i-)+a[][i]*(*i-);
ans=max(ans,cnt+sum[][i+]+(s[n]-s[i])*(*i));
}
}
printf("%lld\n",ans);
return ;
}
cf 1016C的更多相关文章
- ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'
凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- CF memsql Start[c]UP 2.0 A
CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...
- CF memsql Start[c]UP 2.0 B
CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
- CF #375 (Div. 2) D. bfs
1.CF #375 (Div. 2) D. Lakes in Berland 2.总结:麻烦的bfs,但其实很水.. 3.题意:n*m的陆地与水泽,水泽在边界表示连通海洋.最后要剩k个湖,总要填掉多 ...
随机推荐
- nginx一个简单的反向代理设置
location /aaaaa/ { proxy_pass http://localhost:8080/aaaaa/; } 经过配置,现在访问 http://localhost/aaaaa/ 就会 ...
- c++笔记3
一基本语法: 1.1 字符串:支持标准C的 const char* pch=0/"";//不指向任何对象和指向空字符串.C++提供的string类可提供字符串的所有操作,最好是融合 ...
- B. Batch Sort
http://codeforces.com/contest/724/problem/B 被坑了,一开始以为如果有一行已经是排好序了,然后有一行需要转换的次数 >= 2的话,那就直接no了. 因为 ...
- CellSet 遍历
CellSet 结构: 查询MDX: SELECT NON EMPTY {{ {{ {{ {{ {{ AddCalculatedMembers([店铺.店铺ID].[店铺ID].Members)}} ...
- MVC View与Controller分离
新建了一个 Separate 解决方案, 如下图 Separate.UI UI层. 引用 Separate.Home Separate.Home 把Home控制器分享到 一个类库中 并引用(Sy ...
- JSONModel 简单例子
// ProductModel.h // JSONModel // // Created by 张国锋 on 15/7/20. // Copyright (c) 2015年 张国锋. All righ ...
- 3、HTTP content-type
HTTP content-type Content-Type,内容类型,一般是指网页中存在的Content-Type,用于定义网络文件的类型和网页的编码,决定浏览器将以什么形式.什么编码读取这个文件, ...
- Python+selenium之获取请求信息
basicConfig()所捕获的log信息.不过其开启的debug模式只能捕获到客户端像服务器发送的post()请求,而无法获取服务器所返回的应答信息. from random import ran ...
- HDU 2149 Public Sale 拍卖(巴什博弈)
思路:只要能给对方留下n+1,我就能胜,否则败. #include <iostream> #include <cstdio> using namespace std; int ...
- 后台登录验证(Tokens/JSON Web Tokens(JWT) 的认证机制)
sessionid不支持跨域,浏览器也不能禁止cookie(禁止以后sessionid还有什么用) 单点登录问题,即时SessionID一样,也无法跨域获取到数据 占坑