Codeforces485D(SummerTrainingDay01-K)
D. Maximum Value
You are given a sequence a consisting of n integers. Find the maximum possible value of
(integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj.
Input
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·105).
The second line contains n space-separated integers ai (1 ≤ ai ≤ 106).
Output
Print the answer to the problem.
Examples
input
3
3 4 5
output
2
//2017-08-17
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; const int N = ;
const int M = ;
//book[i]记录i是否出现过,pre[i]表示比i小的出现过的最大的数
int a[N], n, book[M], pre[M]; int main()
{
while (scanf("%d", &n) != EOF)
{
memset(book, , sizeof(book));
for (int i = ; i < n; i++){
scanf("%d", &a[i]);
book[a[i]] = ;
}
sort(a, a + n);
n = unique(a, a+n)-a;
int ans = , maxinum = (a[n-]<<), ptr = ;
for(int i = ; i <= maxinum; i++){
pre[i] = ptr;
if(book[i])ptr = i;
}
for (int i = ; i < n; i++){
for (int j = a[i]<<; j <= maxinum; j+=a[i]){
ans = max(ans, a[i]-j+pre[j]);
}
}
printf("%d\n", ans);
}
return ;
}
Codeforces485D(SummerTrainingDay01-K)的更多相关文章
- django模型操作
Django-Model操作数据库(增删改查.连表结构) 一.数据库操作 1.创建model表
- 基于改进人工蜂群算法的K均值聚类算法(附MATLAB版源代码)
其实一直以来也没有准备在园子里发这样的文章,相对来说,算法改进放在园子里还是会稍稍显得格格不入.但是最近邮箱收到的几封邮件让我觉得有必要通过我的博客把过去做过的东西分享出去更给更多需要的人.从论文刊登 ...
- 【开源】专业K线绘制[K线主副图、趋势图、成交量、滚动、放大缩小、MACD、KDJ等)
这是一个iOS项目雅黑深邃的K线的绘制. 实现功能包括K线主副图.趋势图.成交量.滚动.放大缩小.MACD.KDJ,长按显示辅助线等功能 预览图 最后的最后,这是项目的开源地址:https://git ...
- 找到第k个最小元----快速选择
此算法借用快速排序算法. 这个快速选择算法主要利用递归调用,数组存储方式.包含3个文件,头文件QuickSelect.h,库函数QuickSelect.c,测试文件TestQuickSelect. 其 ...
- BZOJ 3110: [Zjoi2013]K大数查询 [树套树]
3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 6050 Solved: 2007[Submit][Sta ...
- 二次剩余、三次剩余、k次剩余
今天研究了一下这块内容...首先是板子 #include <iostream> #include <stdio.h> #include <math.h> #incl ...
- [LeetCode] Longest Substring with At Least K Repeating Characters 至少有K个重复字符的最长子字符串
Find the length of the longest substring T of a given string (consists of lowercase letters only) su ...
- K近邻法(KNN)原理小结
K近邻法(k-nearst neighbors,KNN)是一种很基本的机器学习方法了,在我们平常的生活中也会不自主的应用.比如,我们判断一个人的人品,只需要观察他来往最密切的几个人的人品好坏就可以得出 ...
- YYStock开源----iOS股票K线绘制第二版
新的股票绘制粗来啦,欢迎围观star的说(*^__^*) 嘻嘻-- 捏合功能也准备完善了 Github:https://github.com/yate1996/YYStock 长按分时图+五档图 分时 ...
- k近邻算法(knn)的c语言实现
最近在看knn算法,顺便敲敲代码. knn属于数据挖掘的分类算法.基本思想是在距离空间里,如果一个样本的最接近的k个邻居里,绝大多数属于某个类别,则该样本也属于这个类别.俗话叫,"随大流&q ...
随机推荐
- redis windows版本下载地址(不用hm提供的)
https://github.com/MicrosoftArchive/redis/releases
- Swift5 语言参考(一) 关于语言参考
本系列文章的这一部分描述了Swift编程语言的形式语法.此处描述的语法旨在帮助您更详细地理解语言,而不是允许您直接实现解析器或编译器. Swift语言相对较小,因为Swift代码中几乎无处不在的许多常 ...
- ASM路径问题导致数据库不能正常启动 -- 报:ORA-03113: end-of-file on communication channel
环境描述: 操作系统版本:Red Hat Enterprise Linux Server release 6.5 (Santiago) 数据库版本:Oracle 11.2.0.4 RAC 场景描述: ...
- Windows下调试hadoop
1. 本地模式 本地模式下调试hadoop:下载winutils.exe和hadoop.dll hadoop.lib等windows的hadoop依赖文件放在D:\proc\hadoop\bin目 ...
- (转)python WSGI框架详解
原文:https://www.cnblogs.com/shijingjing07/p/6407723.html?utm_source=itdadao&utm_medium=referral h ...
- ABP集成WIF实现单点登录
ABP集成WIF实现单点登录 参考 ojlovecd写了三篇关于WIF文章. 使用WIF实现单点登录Part III —— 正式实战 使用WIF的一些开源示例. https://github.com/ ...
- Window服务与Quartz.NET
Quartz.NET: http://quartznet.sourceforge.net/ (现为2.2版本) Sourceforge:http://sourceforge.net/projects/ ...
- Linux的Bash Shell详解
一.Bash Shell概述 1.什么是bash bash是Bourne Again Shell的简称,是从unix系统中的sh发展而来的,是用户和Linux内核交互的工具,用户通过b ...
- Java总结:字符串详解
更新时间:2018-1-6 21:20:39 更多请查看在线文集:http://android.52fhy.com/java/index.html String 字符串创建 String str1=& ...
- 解决 https 证书验证不通过的问题
解决的办法:忽略服务端和客户端的证书校验即可.java 提供的相关的类. 通过重写TrustManager的checkClientTrusted(检查客户端证书信任)和checkServerTrust ...