J: A Simple Problem

Submit Page   Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 87     Solved: 12


Description

在一个由N个整数组成的数列中,最多能找到多少个位置连续的整数且其中的最大值与最小值之差不超过K呢?

Input

输入包含若干组数据。每组数据的第一行有2个正整数,N(1<=N<=10^6),K(0<=K<=10^6),其中N、K的含义同上,接下来一行一共有N个32位有符号整数(32-bit signed integer),依次描绘了这个数列中各个整数的值。

Output

对于每组数据,输出一个正整数,表示在这个数列中最多能找到多少个位置连续的整数且其中的最大值与最小值之差不超过K。

Sample Input

4 2
3 1 5 2 3 2
3 1 2

Sample Output

2
3
#include<cstdio>
#include<iostream>
#include<cmath>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
char s[],c[];
const int MAXN=;
ll A[MAXN];
int main(){
ll x,y;
ll maxx=-,minn=;
/*set和multiset 会根据特定的排序准则,
自动将元素排序。两者不同之处,
在于multiset允许元素重复,而set不允许重复*/
multiset<ll> ss;
while(scanf("%lld%lld",&x,&y) !=EOF){
for(int i=;i<x;i++){
scanf("%lld",&A[i]);
}
ll nlen=;
ll maxi=,mini=;
ll left=,right=;
ss.insert(A[]);
while(right != x){
maxx=*(--ss.end());
minn=*ss.begin();
if(maxx-minn<=y){
nlen=right-left+>nlen?right-left+:nlen;
ss.insert(A[++right]);
}
else{
auto pos=ss.find(A[left++]);
ss.erase(pos);
}
}
cout<<nlen<<endl;
ss.clear();
}
return ;
}

CSUOJ 1170 A sample problem的更多相关文章

  1. CSU OJ 1340 A Sample Problem

    Description My girlfriend loves 7 very much, she thinks it is lucky! If an integer contains one or m ...

  2. CSUOJ 1341 String and Arrays

    Description 有一个N*N的字符矩阵,从上到下依次记为第1行,第2行,--,第N行,从左至右依次记为第1列,第2列,--,第N列.    对于这个矩阵会进行一系列操作,但这些操作只有两类:  ...

  3. A trip through the Graphics Pipeline 2011_08_Pixel processing – “fork phase”

    In this part, I’ll be dealing with the first half of pixel processing: dispatch and actual pixel sha ...

  4. MYSQL异常和错误机制

    BEGIN ; ; ; START TRANSACTION; call put_playerbehavior(i_playerid,i_gameid,i_channelid,i_acttime,@a) ...

  5. [译]Java 设计模式之适配器

    (文章翻译自Java Design Pattern: Adapter) 适配器模式在现在的Java框架中被频繁的用到. 当你想去使用一个存在的类而且它的接口和你需要的不吻合,或者是你想去创建一个可复用 ...

  6. csu oj 1344: Special Judge

    Description Given a positive integer n, find two non-negative integers a, b such that a2 + b2 = n. I ...

  7. csu oj 1342: Double

    Description 有一个由M个整数组成的序列,每次从中随机取一个数(序列中每个数被选到的概率是相等的)累加,一共取N次,最后结果能被3整除的概率是多少? Input 输入包含多组数据.     ...

  8. csu oj 1341 string and arrays

    Description 有一个N*N的字符矩阵,从上到下依次记为第1行,第2行,……,第N行,从左至右依次记为第1列,第2列,……,第N列. 对于这个矩阵会进行一系列操作,但这些操作只有两类: (1) ...

  9. Null Hypothesis and Alternate Hypothesis

    1.Null Hypothesis Overview 零假设,H0是普遍接受的事实;这与备择假设(alternate hypothesis)正好相反.研究人员努力否定.驳斥零假设.研究人员提出了另一种 ...

随机推荐

  1. VS中为非控制台程序提供控制台输出窗口

    /************************************************************************/ /* 模块名:ConsoleAdapter 文件名 ...

  2. SuperSocket.WebSocket.WebSocketServer.Setup无法启动

    新学一词:达克效应.引出一句:"无知要比知识更容易产生自信."-- 查尔斯·达尔文 写在前面 在三亚呆了半个月了,三亚的冬天好热啊,让我回忆起了放暑假时下午百无聊赖的时光 { 一睡 ...

  3. Error when Building GPU docker image for caffe: Unsupported gpu architecture 'compute_60'

    issue: Error when Building GPU docker image for caffe: Unsupported gpu architecture 'compute_60' rea ...

  4. Express入门介绍vs实例讲解

    下午在团队内部分享了express相关介绍,以及基于express的实例.内容提纲如下. 什么是Express 为什么要用Express 路由规则 一切皆中间件 实例:Combo Applicatio ...

  5. linux下tomcat指定jdk和配置运行参数

    一.指定运行jdk 1)set classpath.sh和catalina.sh中写入: export JAVA_HOME=/usr/local/java/jdk1.8.0_121 export JR ...

  6. Monkey稳定性测试

    1.环境准备:Android SDK环境配置 2.手机连接/模拟器连接 : 1)手机打开开发者模式并允许USB连接 2)校验手机是否连接:打开cmd 输入 adb devices 3.查找apk包名及 ...

  7. 唐雎(jū)不辱使命

    唐雎(jū)不辱使命 ​选自<战国策> 秦王使人谓安陵君曰:“寡人欲以五百里之地易安陵,安陵君其许寡人.”安陵君曰:“大王加惠,以大易小,甚善.虽然,受地于先生,愿终守之,弗敢易.”秦王不 ...

  8. PAT甲题题解-1104. Sum of Number Segments (20)-(水题)

    #include <iostream> #include <cstdio> #include <algorithm> #include <string.h&g ...

  9. akm

    队名--牛肉面不要牛肉不要面 队伍成员 211406285 林志松 [队长兼前端开发] 211606368 林书浩 [系统设计] 211606357 陈远军 [UI美工] 211606335 吴沂章 ...

  10. 《Linux内核设计与实现》第四章学习笔记——进程调度

                                                                        <Linux内核设计与实现>第四章学习笔记——进程调 ...