DIFFICULTY:
CAKEWALK PREREQUISITES:
None PROBLEM:
You’re given N pairs of integers (p_i, s_i) where 1 \leq p_i \leq 11. For each p_i<9 calculate maximum number of s_i with this p_i and output the sum of these numbers. QUICK EXPLANATION:
You should basically do what’s written in the statement. EXPLANATION:
Maintain array mx with maximum scores for each problem and output the sum of first 9 elements.
void solve() {
int n;
cin >> n;
vector<int> mx(11);
for(int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
mx[p] = max(mx[p], s);
}
cout << accumulate(begin(mx), begin(mx) + 9, 0LL) << endl;
}
AUTHOR’S AND TESTER’S SOLUTIONS:
Author’s solution can be found here.
Tester’s solution can be found here.
Editorialist’s solution can be found here.
int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
// vector mx(11);
vector ans(8);
for(int i = 0; i < n; i++) {
int p, s;
cin >> p >> s;
p--;
if (p < 8) {
ans[p] = max(ans[p], s);
}
}
int sum = 0;
for (int i = 0; i < 8; i++)
sum += ans[i];
cout << sum << '\n';
}
return 0;
}