Zoj#3202:second-price Auction

Source: Internet
Author: User

Memory limit:32768kb
64bit IO Format:%lld &%llu

Description

Do you know Second-price auction? It ' s very simple but famous. In a second-price auction, each potential buyer privately submits, perhaps in a sealed envelope or over a secure connectio N, his (or hers) bid for the object to the auctioneer. After receiving all the bids, the auctioneer then awards the object to the bidder with the highest bid, and charges him (O R her) The amount of the Second-highest bid.

Suppose you "re the auctioneer and you had received all the bids, you should decide the winner and the amount of money he (or she) should pay.

Input

There is multiple test cases. The first line of input contains an integer t (t <=), indicating the number of test cases. Then T test cases follow.

Each test case contains-lines:the first line of all test case contains only one integer N, indicating the number of Bidders. (2 <= N <= 100) The second line of all test case contains N integers separated by a space. The i-th integer Pi indicates the i-th bidder ' s bid. (0 < Pi <= 60000) Assume that's the highest bid is unique.

Output

For each test case, the output a line containing the integers x and y separated by a space. It indicates that the x-th bidder are the winner and the amount of money he (or she) should pay is Y.

Sample Input

2
3
3 2 1
2
6 {

Sample Output

1 2
2 4

Source
The 6th Zhejiang Provincial Collegiate Programming Contest

The AC code is as follows:

 #include <iostream> #include <algorithm> using namespace std; int main () {int T;
    cin>>t;
        while (t--) {int n,a[101],b[101];
        cin>>n;
            for (int i=0;i<n;i++) {cin>>a[i];
        B[i]=a[i];
        } sort (b,b+n);
        for (int i=0;i<n;i++) {if (a[i]==b[n-1]) cout<<i+1<< "";
    } cout<<b[n-2]<<endl;
} return 0; }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.