From 83061a69780d9daf3a10fa1803e49da03fa5b6ad Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Sun, 12 Jun 2022 22:48:16 +0800 Subject: [PATCH] B - Promo https://codeforces.com/contest/1697/submission/160295805 --- Codeforces/1697/B/B.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 Codeforces/1697/B/B.cpp diff --git a/Codeforces/1697/B/B.cpp b/Codeforces/1697/B/B.cpp new file mode 100644 index 00000000..20b4d6d5 --- /dev/null +++ b/Codeforces/1697/B/B.cpp @@ -0,0 +1,38 @@ +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e5 + 5; + +int n, q, p[N]; +long long s[N]; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> q; + + for (int i = 1; i <= n; i++) { + cin >> p[i]; + } + + std::sort(p + 1, p + 1 + n, std::greater()); + + for (int i = 1; i <= n; i++) { + s[i] = s[i - 1] + p[i]; + } + + while (q--) { + int x, y; + + cin >> x >> y; + + cout << s[x] - s[x - y] << endl; + } + + return 0; +}