The problem is really ad-hoc, but makes sense if you read it reeeeeally carefully.
You are given an P amount of problems, and a S amount of subtask.
For each subtask you have 2 data:
You are told to sort the problems according to the difficulty, which is calculated by this:
- Subtasks should be sorted by score
- Each subtask has an amount of right attempts
- If a bigger score has less right attempts, then you add n += 1 to the difficulty (which makes sense, if a score is bigger then it should be more difficult, so it should have less right attempts)
Let’s take these 3 problems with 3 subtasks of the example:
16 24 60
498 861 589
14 24 62
72 557 819
16 15 69
435 779 232
You first have to join each subtask with their right attempts like this:
P1 = [(16,498), (24,861), (60,589)]
P2 = [(14,72), (24,557), (62,819)]
P3 = [(16,435), (15,779), (69,232)]
Problem ask you to sort each problem by its score, so:
P1 = [(16,498), (24,861), (60,589)]
P2 = [(14,72), (24,557), (62,819)]
P3 = [(15,779), (16,435), (69,232)]
Now, a problem is harder if the number of right attempts is decreasing, calculated by
n += 1
if
P[i][1] > P[i+1][1]
where:
P are the problems
i is the index of each subtask.
1 is the number of right attempts.
Therefore, the “n” number of each problem is:
P1 = 1 (861 is bigger than 589)
P2 = 0
P3 = 2 (779 is bigger than 435, and 435 is bigger than 232)
Then, you are asked to sort them increasingly according to their n value, so:
P2 = 0
P1 = 1
P3 = 2
Finally, you are asked to print THE PROBLEM index increasingly, accordingly to its n value, do not print the n value, so:
2
1
3
If a problem has the same n, sort them by index.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<pair<ll,ll>> probs;
ll P, S;
cin >> P >> S;
for(ll i=0; i<P; i++){
vector<ll> score(S);
vector<ll> right(S);
for(ll j=0; j<S; j++){
cin >> score[j];
}
for(ll j=0; j<S; j++){
cin >> right[j];
}
vector<pair<ll,ll>> subs;
for(ll j=0; j<S; j++){
subs.push_back(make_pair(score[j], right[j]));
}
sort(subs.begin(), subs.end(), [](pair<ll,ll> a, pair<ll,ll> b){
if (a.first < b.first)
return true;
else if (a.first > b.first)
return false;
else{
return a.second < b.second;
}
});
ll n = 0;
for(ll j=0; j<S-1; j++){
if (subs[j].second > subs[j+1].second)
n++;
}
probs.push_back(make_pair(n,i+1));
}
sort(probs.begin(), probs.end(), [](pair<ll,ll> a, pair<ll,ll> b){
if (a.first < b.first)
return true;
else if (a.first > b.first)
return false;
else{
return a.second < b.second;
}
});
for(ll i=0; i<P; i++){
cout << probs[i].second << "\n";
}
}