You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
840 B
C++

#define _CRT_SECURE_NO_WARNINGS
#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;
}