ZeroJudge K466: Score Analysis

The recent mid-term exams have just been completed. To encourage the students in the class, the teacher wants to especially award gifts to the students who have made the most progress in the past mid-term exams. In addition, the teacher also wants to find out the students who have regressed the most and pay more attention to their learning situation.

The teacher will record the sum of the scores that have improved compared to the previous test as the student's progress margin and the sum of the scores that have regressed compared to the previous test as the student's regression margin.

For example, if a student's scores for the first five mid-term exams are (80, 90, 60, 70, 65), their progress scores for each exam compared to the previous exam are (10, 0, 10, 0), respectively. Therefore, their progress margin is 20. Their regression scores for each exam compared to the previous exam are (0, 30, 0, 5), respectively. Therefore, their regression margin is 35.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The input consists of two integers N and M (3 ≤ N ≤ 1000, 2 ≤ M ≤ 100) on the first line, representing the number of students and the number of exams, respectively. Following this, there are N columns, each containing M numbers Si (1 ≤ Si ≤ 100, 1 ≤ i ≤ M), representing the exam scores of student i over the M exams.The output should consist of two columns:
First column: Represents the seat number of the student who has shown the most progress.
Second column: Represents the seat number of the student who requires the most attention.
In case there are multiple students with the highest progress margin or the highest regression margin, output the student with the smallest seat number.).
3 5
80 90 60 70 65
70 60 65 60 55
40 50 60 70 80
3
1
3 3
74 44 98
11 75 14
62 19 32
2
2
4 4
33 51 10 76
69 90 69 91
17 55 59 64
46 82 60 26
1
4
8 3
3 83 13
92 45 67
70 19 11
46 78 86
98 61 26
68 78 40
48 94 3
44 9 39
1
7
ZeroJudge K466 Sample Test Cases

Thought Process

Store each student's score in an array.
While collecting data, compare the current data to the previous data to determine if it is larger or smaller.
Declare two variables, up and down, and initialize them to 0.
If the current data represents progress, add the progress margin to up. Otherwise, add the regression margin to down.

After calculating the progress and regression margins for a student, determine whether they have the highest progress or regression margin in the entire class. Since there might be instances where students share the same progress or regression margins, use the > operator for comparison. In cases of equal margins, prioritize the student with a smaller seat number (i.e.,

Sample Code-ZeroJudge K466: Score Analysis

#include <iostream>
#include <vector>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    int increase = -1, increase_num = 0, decrease = -1, decrease_num = 0;
    for (int i = 0; i<N; i++) {
        vector<int>num;
        int up = 0, down = 0;
        for (int j = 0; j<M; j++) {
            int tmp;
            cin >> tmp;
            num.push_back(tmp);
            if (j > 0) {
                if (num[j] > num[j-1]) up += num[j] - num[j-1];
                if (num[j] < num[j-1]) down += num[j-1] - num[j];
            }
        }
        if (up > increase) {
            increase = up;
            increase_num = i+1;
        }
        if (down > decrease) {
            decrease = down;
            decrease_num = i+1;
        }
    }
    cout << increase_num << "\n" << decrease_num << "\n";
}

//ZeroJudge K466
//Dr. SeanXD

Comments