This is the problem I am trying to solve:
https://www.codechef.com/problems/ENTEXAM
This is my solution:
https://www.codechef.com/viewsolution/19393110
When I compile my solution, I am getting wrong answer. While trying to figure out why, I noticed that when I am sorting the total score in ascending order, it doesn't sort 0. Why is this the case?
The code below gives only the output of total score in ascending order
#include<iostream>
int main()
{
int N, K, E, M, T, i, k, j, s[4], L[10000], temp;
std::cin >> T;for (i = 0; i < T; i++)
{
std::cin >> N >> K >> E >> M;
for (j = 0; j < N; j++)
{
if (j != N - 1)
{
L[j] = 0;
for (k = 0; k < E; k++)
{
std::cin >> s[k];
}
for (k = 0; k < E; k++)
{
L[j] = L[j] + s[k];
}
}
else
{
L[j] = 0;
for (k = 0; k < E - 1; k++)
{
std::cin >> s[k];
}
for (k = 0; k < E - 1; k++)
{
L[j] = L[j] + s[k];
}
}
}
for (j = 0; j < N-2; j++)
{
for (k = j + 1; k < N - 2; k++)
{
if (L[j] >= L[k])
{
temp = L[j];
L[j] = L[k];
L[k] = temp;
}
}
}
for (j = 0; j < N; j++)
std::cout << L[j] << std::endl;
}
system("pause");
std::cin.get();
}Asked by: Abhinav_Lugun on April 7, 2019, 6:34 p.m. Last updated on April 7, 2019, 6:34 p.m.