-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathA. Robin Helps.cpp
More file actions
50 lines (40 loc) · 1.14 KB
/
A. Robin Helps.cpp
File metadata and controls
50 lines (40 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, q;
cin >> n >> q;
vector<int> a(n);
// Read target scores
for (int i = 0; i < n; i++) {
cin >> a[i];
}
while (q--) {
int l, r;
cin >> l >> r;
l--; r--; // Convert to 0-based index
// Extract the relevant scores
vector<int> scores(a.begin() + l, a.begin() + r + 1);
sort(scores.rbegin(), scores.rend()); // Sort in descending order
long long robinScore = 0, sheriffScore = 0;
// Calculate scores for Robin and Sheriff
for (int i = 0; i < scores.size(); i++) {
if (i % 2 == 0) {
robinScore += scores[i];
} else {
sheriffScore += scores[i];
}
}
if (sheriffScore >= robinScore) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
}
return 0;
}