标签:bsp user name namespace color 分类 pid button text
5 6
1 1 1 1 1
2
对于15%的数据,n≤1000
对于30%的数据,n≤5000
对于50%的数据,n,k≤105
对于70%的数据,n≤105
对于100%的数据,n≤106,1≤a[i],k≤109
#include "bits/stdc++.h" using namespace std; typedef long long ll; const int maxn = 1e6 + 1000; ll a[maxn]; int n, k; ll check(ll mid) { int j = 0; ll res = 0; for (int i = 1; i <= n; i++) { while (a[i] - a[j] > mid) j++; res += i - j; } return res; } int main() { //freopen("input.txt", "r", stdin); scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf("%lld", &a[i]); a[i] += a[i - 1]; } ll l = 0, r = a[n], mid; while (l < r) { mid = (l + r) >> 1; if (check(mid) >= k) r = mid; else l = mid + 1; } printf("%lld\n", r); return 0; }
标签:bsp user name namespace color 分类 pid button text
原文地址:https://www.cnblogs.com/albert-biu/p/10345467.html