1306. Sequence Median
Time limit: 1.0 secondMemory limit: 1 MB
Language limit: C, C++, Pascal
Input
The first line of input contains the only integer number N ― the length of the sequence. Sequence itself follows in subsequent lines, one number in a line. The length of the sequence lies in the range from 1 to 250000. Each element of the sequence is a positive integer not greater than 231?1 inclusive.Output
You should print the value of the median with exactly one digit after decimal point.Sample
| input | output |
|---|---|
4 3 6 4 5 |
4.5 |
#include#include #include #include #include #include #include using namespace std; priority_queue , greater > pq; int main(){ int n; while(~scanf("%d",&n)){ int cnt = n/2+1; while(!pq.empty()) pq.pop(); for(int i = 0; i < n; i++){ int d; cin >> d; if(pq.size()