I wrote the EGE on computer science, today the results became known. For some reason, in C4 I was given only 1 point out of 4, although the task is the simplest. Unfortunately, I do not have the exact wording of the task, so I will write from memory. First, the number N (the number of particles) is entered, then the N velocities of the particles (according to the condition from -10000 to 10000). It is necessary to derive the product of the two highest speeds. And it needs to be done effectively in memory and calculations. Here is my code (right from my work):
#include <iostream> using namespace std; int main() { int N; cin >> N; int m[2]={-10000, -10000}; for(int i=0; i<N; i++) { int mi=(m[1]<m[0]); int v; cin >> v; m[mi]=(m[mi]<v)? v: m[mi]; } cout << m[0]*m[1]; return 0; }
I checked it on my computer, everything works fine. The program is effective because it does not add all the numbers to the array, but counts everything as you enter numbers. If you do not find an error in the algorithm, I will go on appeal. Either I misunderstood the condition of the problem (here you certainly will not help me), or the verifiers did not like the smiley (m[1]<m[0])
, or they didn’t check my additional answer form on which the second half was written solutions.
Update
I have other suspicions here. It is possible that my code was not checked at all, because the organizer in the PES incorrectly wrote the additional form number and boldly corrected the number 7 to 3. It is possible that the computer accepted this number as 8 and because of this checked only part of the task on the first form, where Algorithm written in Russian language. This is confirmed by the fact that in the evaluation criteria it is written that one point is given if “according to the given text of the decision it is clear that the subject understands what stages the problem should be solved”. Just the fact that I downloaded all my forms on the Internet contradicts this.
Update 2
Everything, found an error (see my answer). Everything cleared up, I will not go on appeal.
northerner
The algorithm is very bad. Really bad. Just 1 point. And yes, I am an expert exam.
Is that better?
#include <iostream> using namespace std; int main() { int N; cin >> N; int m[2]={-10000, -10000}; int n[2]={10000, 10000}; for(int i=0; i<N; i++) { int mi=(m[1]<m[0]), ni=(n[1]>n[0]); int v; cin >> v; if(m[mi]<v) m[mi]=v; if(n[ni]>v) n[ni]=v; } cout << max(m[0]*m[1], n[0]*n[1]); return 0; }