6 条题解
-
0
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.StringTokenizer;
public class Main { public static void main(String[] args) throws IOException { FastScanner fs = new FastScanner(); PrintWriter out = new PrintWriter(System.out);
int n = fs.nextInt(); int k = fs.nextInt(); int[] s = new int[n + 1]; for(int i = 0;i < n;i++) { s[i + 1] = s[i] + fs.nextInt(); } int maxNum = 0; for(int r = k + 1;r < n + 1;r++) { maxNum = Math.max(maxNum, s[r] - s[r - k - 1]); } out.println(maxNum); out.flush(); } static class FastScanner { BufferedReader br; StringTokenizer st; public FastScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } boolean hasNext() throws IOException { while (st == null || !st.hasMoreTokens()) { String line = br.readLine(); if (line == null) return false; st = new StringTokenizer(line); } return true; } public String next() throws IOException { hasNext(); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public String readLine() throws IOException { return br.readLine(); } }}
-
0
#include<bits/stdc++.h> using namespace std; int a[1000005]; int sum[1000005]; int ans=0; int main() { ios::sync_with_stdio(false); cin.tie(0); int n,k; cin>>n>>k; for(int i=1;i<=n;++i) { cin>>a[i]; sum[i]=sum[i-1]+a[i]; } for(int i=1;i<=n-k;++i) { ans=max(ans,(sum[i+k]-sum[i-1])); } cout<<ans; } -
0
import sys data = sys.stdin.buffer.read().split() n = int(data[0]) k = int(data[1]) waters = list(map(int, data[2:2 + n])) len_waters = len(waters) pre_sum=[0]*(len_waters+1) for i in range(1,len_waters+1): pre_sum[i]=pre_sum[i-1]+waters[i-1] max_water=0 for p in range(1,len_waters+1): start=max(1,p-k) total = pre_sum[p] - pre_sum[start - 1] max_water = max(max_water, total) print(max_water)
-
0
import sys data = sys.stdin.buffer.read().split() n = int(data[0]) k = int(data[1]) waters = list(map(int, data[2:2 + n])) window_sum=0 len_waters = len(waters) max_waters = 0 left=0 right=0 while right<len_waters: c=waters[right] window_sum+=c right+=1 while right-left>k+1: window_sum-=waters[left] left+=1 max_waters=max(max_waters,window_sum) print(max_waters)
- 1
信息
- ID
- 160
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 2
- 标签
- 递交数
- 432
- 已通过
- 180
- 上传者