http://codeforces.com/problemset/problem/731/F

其实是暴力枚举,但是有些小技巧,直接保存每个数的数量。

枚举每个起点时,然后依次加上起点大小的分段的数量的值,用前缀和效率很高,并且能巧妙跳过重复元素。

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; int cnt[] = {},n; int main()
{
scanf("%d",&n);
int temp,maxx = ;
while(n--)
{
scanf("%d",&temp);
maxx = max(maxx,temp);
cnt[temp]++;
}
for(int i = ;i <= maxx;i++) cnt[i] += cnt[i-];
long long ans = ,tempmax;
for(int i = ;i <= maxx;i++)
{
if(cnt[i] != cnt[i-])
{
tempmax = ;
for(int j = i;j <= maxx;j += i) tempmax += (long long)j*(cnt[min(j+i-,maxx)]-cnt[j-]);
ans = max(tempmax,ans);
} }
printf("%I64d\n",ans);
return ;
}

Codeforces_731_F的更多相关文章

随机推荐

  1. 东拼西凑完成一个“前端框架”(5) - Tabs操作

    目录 东拼西凑完成一个后台 "前端框架" (1) - 布局 东拼西凑完成一个后台 "前端框架" (2) - 字体图标 东拼西凑完成一个"前端框架&qu ...

  2. 程序员必知的技术官网系列--mysql篇

    mysql 官网 https://www.mysql.com/ 官网布局很简单, 其中常用的两块就是下载和文档这两块, 其中下载没什么可讲的, 本次重点依旧是文档. 首页 mysql 文档导航页 ht ...

  3. Linux学习_菜鸟教程_1

    Linux系统启动过程:内核的引导 .运行init.系统初始化.建立终端.用户登录系统 内核引导:计算机开机,然后BIOS开机自检,按照BIOS中设置的启动设备(通常是硬盘)来启动. 操作系统接管硬件 ...

  4. css3实现左右div高度自适应且内容居中对齐

    主要运用了css3的弹层布局,直接上代码: 效果:左边盒子宽度固定.内容居中对齐.与右侧盒子高度相等,右侧自动缩放 html: <div class="main"> & ...

  5. Inception V1、V2、V3和V4

    Inception模块分为V1.V2.V3和V4. V1(GoogLeNet)的介绍 论文:Going deeper with convolutions 论文链接:https://arxiv.org/ ...

  6. mongo windows 安装

    下载安装包 一路next 打开cmd 或者 power shell 准备本地目录. D: #进入d盘 md data #创建目录 data cd data #进入目录 data md config # ...

  7. CF - 高精度 + 贪心

    Last year Bob earned by selling memory sticks. During each of n days of his work one of the two foll ...

  8. springcloud复习1

    1.SpringCloud是什么?SpringCloud=分布式微服务架构下的一站式解决方案,是各个微服务架构落地技术的集合体,俗称微服务全家桶. 2.SpringCloud和SpringBoot是什 ...

  9. 测试必备之Java知识(四)—— 线程相关

    线程相关 Java多线程实现方式 继承Thread,实现Runnable接口,实现Callable接口(能抛异常且有返回值,不常用) 为什么有了继承Thread方式还要有Runnable接口方式 实现 ...

  10. 缓存读写策略 - Cache Aside.md

    场景描述 比如一条数据同时存在数据库.缓存,现在你要更新此数据,你会怎么更新? 先更新数据库?还是先更新缓存? 其实这两种方式都有问题. (1)先更新数据库,后更新缓存 这样会造成数据不一致. A 先 ...