网站建设 招标,wordpress 设置头像api,手机看电影的网站建设,备案域名解析链接#xff1a;登录—专业IT笔试面试备考平台_牛客网 来源#xff1a;牛客网
题目描述
读入n#xff0c;xn#xff0c;xn#xff0c;x,给出nnn个数a[1],a[2],……,a[n]a[1],a[2],……,a[n]a[1],a[2],……,a[n],求最小的区间[l,r][l,r][l,r]#xff0c;使a[l]a[l1]……链接登录—专业IT笔试面试备考平台_牛客网 来源牛客网
题目描述
读入nxnxnx,给出nnn个数a[1],a[2],……,a[n]a[1],a[2],……,a[n]a[1],a[2],……,a[n],求最小的区间[l,r][l,r][l,r]使a[l]a[l1]……a[r]≥xa[l]a[l1]……a[r]≥xa[l]a[l1]……a[r]≥x若存在相同长度区间输出lll最小的那个
输入描述:
第一行两个数n(1≤n≤10000000),x(1≤x≤10000)
第二行n个数a[i](1≤a[i]≤1000)输出描述:
输出符合条件l,r(保证有解)
示例1
输入
复制10 20 1 1 6 10 9 3 3 5 3 7
10 20
1 1 6 10 9 3 3 5 3 7
输出
复制3 5
3 5 import java.io.*;
import java.util.*;
public class Main{public static PrintWriter out new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));public static Read sc new Read();public static void main(String [] args) throws IOException {int n sc.nextInt();int x sc.nextInt();//输入数组元素int [] arraynew int [n1];for(int i1;in;i)array[i]sc.nextInt();//startint retInteger.MAX_VALUE;//最小距离int a-1,b-1;//保存最后结果int left1,right1,sum0;while (rightnleftn){if(sumx)sumarray[right];while (sumx){if(right-left1ret){aleft;bright;retright-left;}sumsum-array[left];left;}right;}System.out.println(a b);}
}
class Read // 自定义快速读入
{StringTokenizer st new StringTokenizer();BufferedReader bf new BufferedReader(new InputStreamReader(System.in));String next() throws IOException{while(!st.hasMoreTokens()){st new StringTokenizer(bf.readLine());}return st.nextToken();}String nextLine() throws IOException{return bf.readLine();}int nextInt() throws IOException{return Integer.parseInt(next());}long nextLong() throws IOException{return Long.parseLong(next());}double nextDouble() throws IOException{return Double.parseDouble(next());}
}