Wed, 30 Jan 2019 16:19:59 GMT

master
大蒟蒻 7 years ago
parent 38f1171eef
commit a4f56bda64

@ -35,3 +35,7 @@ multiset.upper_bound()
### I - Counter Strike
转换为减掉平均值后求出的前缀和的顺序对数。
### J - 区间交
说实话,没怎么看懂题解。望大佬们不吝告知。

@ -2,7 +2,29 @@
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long a[N];
pair<int, int> p[N];
int main()
{
int n, k, m;
while (~scanf("%d%d%d", &n, &k, &m))
{
for (int i = 1; i <= n; i++)
scanf("%lld", a + i), a[i] += a[i - 1];
for (int i = 0; i < m; i++)
scanf("%d%d", &p[i].first, &p[i].second);
sort(p, p + m);
priority_queue<int> h;
long long ans = 0;
for (int i = 0; i < m; i++)
{
h.push(-p[i].second);
if (h.size() < k) continue;
if (h.size() > k) h.pop();
ans = max(ans, a[-h.top()] - a[p[i].first - 1]);
}
printf("%lld\n", ans);
}
return 0;
}

Loading…
Cancel
Save