codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

459B.md (1642B)


      1 Source: https://codeforces.com/problemset/problem/459/B
      2 
      3 B. Pashmak and Flowers
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Pashmak decided to give Parmida a pair of flowers from the garden. There are *n* flowers in the garden and the *i*-th of them has a beauty number *b**i*. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. She wants to have those pairs of flowers that their beauty difference is maximal possible!
     22 
     23 Your task is to write a program which calculates two things:
     24 
     25 1. The maximum beauty difference of flowers that Pashmak can give to Parmida.
     26 2. The number of ways that Pashmak can pick the flowers. Two ways are considered different if and only if there is at least one flower that is chosen in the first way and not chosen in the second way.
     27 
     28 Input
     29 
     30 The first line of the input contains *n* (2 ≤ *n* ≤ 2·105). In the next line there are *n* space-separated integers *b*1, *b*2, ..., *b**n* (1 ≤ *b**i* ≤ 109).
     31 
     32 Output
     33 
     34 The only line of output should contain two integers. The maximum beauty difference and the number of ways this may happen, respectively.
     35 
     36 Examples
     37 
     38 Input
     39 
     40 ```
     41 2  
     42 1 2
     43 ```
     44 
     45 Output
     46 
     47 ```
     48 1 1
     49 ```
     50 
     51 Input
     52 
     53 ```
     54 3  
     55 1 4 5
     56 ```
     57 
     58 Output
     59 
     60 ```
     61 4 1
     62 ```
     63 
     64 Input
     65 
     66 ```
     67 5  
     68 3 1 2 3 1
     69 ```
     70 
     71 Output
     72 
     73 ```
     74 2 4
     75 ```
     76 
     77 Note
     78 
     79 In the third sample the maximum beauty difference is 2 and there are 4 ways to do this:
     80 
     81 1. choosing the first and the second flowers;
     82 2. choosing the first and the fifth flowers;
     83 3. choosing the fourth and the second flowers;
     84 4. choosing the fourth and the fifth flowers.