考虑每个数在最大值内的倍数都求出来大概只有max(ai)ln(max(ai))个。

先排个序,然后对于每个数ai,考虑哪些数字可以变成ai*k。

显然就是区间[ai*k,ai*(k+1))内的数,这个二分一下就好了。

 #include <bits/stdc++.h>
using namespace std; int a[]; int main()
{
int n;
scanf("%d", &n);
for (int i = ; i < n; i++)
scanf("%d", a + i);
sort(a, a + n);
long long ans = ;
int last = -;
for (int i = ; i < n; i++)
{
if (a[i] == last)
continue;
long long temp = ;
for (int j = ; (j - ) * a[i] <= a[n - ]; j++)
{
int down = j * a[i];
int up = (j + ) * a[i];
int *pup = lower_bound(a, a + n, up);
int *pdown = lower_bound(a, a + n, down);
temp += 1LL * j * a[i] * (pup - pdown);
}
ans = max(ans, temp);
last = a[i];
}
printf("%I64d", ans);
return ;
}

Codeforces731F Video Cards的更多相关文章

  1. Codeforces Round #376 (Div. 2) F. Video Cards 数学,前缀和

    F. Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  2. Video Cards

    Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  3. Codeforces Round #376 (Div. 2) F. Video Cards —— 前缀和 & 后缀和

    题目链接:http://codeforces.com/contest/731/problem/F F. Video Cards time limit per test 1 second memory ...

  4. 【19.05%】【codeforces 731F】 Video Cards

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

  5. Codeforces 731 F. Video Cards(前缀和)

    Codeforces 731 F. Video Cards 题目大意:给一组数,从中选一个数作lead,要求其他所有数减少为其倍数,再求和.问所求和的最大值. 思路:统计每个数字出现的个数,再做前缀和 ...

  6. Codeforces Round #376 (Div. 2)F. Video Cards(前缀和)

    题目链接:http://codeforces.com/contest/731/problem/F 题意:有n个数,从里面选出来一个作为第一个,然后剩下的数要满足是这个数的倍数,如果不是,只能减小为他的 ...

  7. Codeforces 731F Video Cards

    题意:给定n个数字,你可以从中选出一个数A(不能对该数进行修改操作),并对其它数减小至该数的倍数,统计总和.问总和最大是多少? 题解:排序后枚举每个数作为选出的数A,再枚举其他数, sum += a[ ...

  8. Codeforces Round #376 (Div. 2) F. Video Cards 数学 & 暴力

    http://codeforces.com/contest/731/problem/F 注意到一个事实,如果你要找一段区间中(从小到大的),有多少个数是能整除左端点L的,就是[L, R]这样.那么,很 ...

  9. CodeForces 731F Video Cards (数论+暴力)

    题意:给定 n 个数,可以对所有的数进行缩小,问你找出和最大的数,使得这些数都能整除这些数中最小的那个数. 析:用前缀和来做,先统计前 i 个数中有有多少数,然后再进行暴力去找最大值,每次都遍历这一段 ...

随机推荐

  1. 使用squid架设自己的代理server

    主要參考了 http://blog.chinaunix.net/uid-20778906-id-540115.html Ubuntu下Squid代理server的安装与配置 1 安装 $ sudo a ...

  2. redux 及 相关插件 项目实战

    目录结构 +-- app | +-- actions | +-- index.js | +-- components | +-- content.js | +-- footer.js | +-- se ...

  3. JAVA设计模式之 原型模式【Prototype Pattern】

    一.概述: 使用原型实例指定创建对象的种类,而且通过拷贝这些原型创建新的对象. 简单的说就是对象的拷贝生成新的对象(对象的克隆),原型模式是一种对象创建型模式. 二.使用场景: 创建新的对象能够通过对 ...

  4. aip接口中对url参数md5加密防篡改的原理

    目前网上所有开放api的网站中,数据的调用都是采用同一种方式,即: http:www.xxx.com/aa=1&bb=2...,原后对这些参数按字典顺序排序后进行md5加密,将md5加密串与接 ...

  5. HDU 2601An easy problem-素数的运用,暴力求解

    id=17433" target="_blank" style="color:blue; text-decoration:none">An ea ...

  6. 电脑突然死机,编译报错dll缺少依赖项

    由于ASP.NET缓存没更新的问题(我的就是这个问题.电脑突然死机导致的). 把这个文件夹下的文件所有删除C:\Windows\Microsoft.NET\Framework\v2.0.50727\T ...

  7. java zip压缩优化版 解决压缩后文件一直被占用无法删除

    最近进行zip操作,从网上找到一个处理方法,但是经过试验存在一些bug,主要是文件流的申明存在问题,导致jvm一直占用文件而不释放,特意把自己修改的发出来,已备记录 import java.io.Bu ...

  8. Multitier architecture

    Multitier architecture - Wikipedia https://en.wikipedia.org/wiki/Multitier_architecture Common layer ...

  9. boogo08---中间件

    package main //中间件1:只允许特定host请求过来 import ( "fmt" "net/http" ) //SingleHost是一个中间件 ...

  10. linunx 下载文件到本地

    1.检查并安装相应的包:yum install lrzsz 2.使用 sz 文件名 现在相应的文件到本地磁盘. 3.上传使用rz 选择相应文件即可.