Opening the reading…
Opening the reading…
TIME AND SPACE COMPLEXITY / ONLINE JUDGE › ONLINE JUDGE
An online judge is a system that receives code, tests it, and returns a result without evaluating your explanation or intent. For the task "read n integers and print their sum," it can give the same input to every submission, observe each program, and compare each result with the required result. This makes evaluation repeatable: two people are judged by the behavior of their programs, not by how convincing their descriptions sound.
For the concrete input 4 followed by 4 2 7 1, a correct program reads four integers, calculates 4 + 2 + 7 + 1, and produces 14. The judge can perform that process automatically whenever code is submitted. The displayed example helps you understand the task, but it is only one test of the program's behavior.
Input:
4
4 2 7 1
Required output:
14For this task, the artifact you submit must be C++ or Java source code that performs the required input-output behavior. The judge needs source code because it can compile that code and run the resulting program with its own input. Sending the number 14 is not enough: 14 is one result you observed, not a program that can read another set of integers and calculate its sum.
A screenshot showing 14 also gives the judge nothing it can execute. A written explanation may show that you understand addition, but it cannot be compiled or tested. Your local run is useful evidence while you are developing, yet the judge sees the submitted source code and the behavior that source code produces.
What must you submit for the sum task so the judge can test it?
Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
The judge checks a submission in stages. First, the source code must compile. If compilation succeeds, the judge runs the program with input 4 and the line 4 2 7 1. While it runs, the judge checks limits such as time and memory. Finally, it compares the program's actual output with the required output character by character.
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int sum = 0;
for (int i = 0; i < n; i++) {
int value;
cin >> value;
sum += value;
}
cout << "Sum = " << sum << '\n';
}This program reads the four values and calculates 14, so its arithmetic is correct. Its actual output is Sum = 14, while the required output is 14. Those strings are different because the words and spaces are part of the output. A program that prints extra labels can therefore receive an output mismatch even when the calculated number is right.
The program calculates the correct sum but prints "Sum = 14". Type the exact required output for the shown input.
cout << "Sum = " << sum << '\n';Checkpoints are not graded. They are here so you catch yourself before the quiz does — stuck, ask the tutor on the right.
The input 4 and the numbers 4 2 7 1 are an example, not a promise that the judge will use only those values. The judge may run undisclosed inputs for the same task, and your program must read the input and print the correct sum for every required test. A program can produce 14 for the shown input while failing when the number of integers changes or when another valid set of integers is supplied.
The program must also finish within the allowed time and memory. A verdict tells you which condition failed, such as compilation, execution, a resource limit, or output comparison. It does not reveal your intended fix. You must use the failed stage and the program's behavior to find what needs to change.