Home > Back-end >  Election game tip WA, asked the great spirit guide
Election game tip WA, asked the great spirit guide

Time:09-26

Problem: enter a n (2 & lt;=n<=100), on behalf of turnout, the next line input n Numbers, each number represents each candidate current votes, votes m<10000, the first number is your votes, requires a digital output, said a total of people from behind you at least get some votes to win the election,
The sample input and output:
Input:
4
1 8 8 8
Output:
6
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
My train of thought is that every time the judge is the first largest, if not, just picking a ticket inside people most votes from behind, though not the fastest algorithm, but I really don't know why will give WRONG ANSWER this prompt, the test cases is not through, seek advice
 # include 
using namespace std;
Bool isMax (int * p, int n) {
Int temp=p [0];
For (int I=1; i If (p [I] & gt;=temp) {return false. }
}
return true;
}
Int main () {
int n;
Cin & gt;> n;
Int * HXZPS=new int [n].
For (int I=0; i HXZPS [I];
Int flag=0;
For (int I=0; i If (HXZPS [I] & gt; 0 {flag++; }
}
If (flag==0) {
return 0;
}
Int count=0;
Int maxi.
while (! IsMax (HXZPS, n)) {
Int temp=0;
For (int I=1; i If (HXZPS [I] & gt; Temp) {
Maxi=I;
Temp=HXZPS [I];
}
}
HXZPS [0] + +; count++;
HXZPS [maxi] -;
}
Cout & lt; & lt; The count & lt; & lt; Endl;
return 0;
}
  • Related