codeforces-386a Second-price Auction

Source: Internet
Author: User
Tags integer numbers

In this problem we consider a special type of an auction, which is called the Second-price auction. As in regular auction n bidders place a bid which was price a bidder ready to pay. The auction is closed, and that's, each bidder secretly informs the organizer of the auction price he's willing to pay. After that, the auction winner are the participant who offered the highest price. However, he pay isn't the price he offers, but the highest price among the offers of other participants (hence the name:the Second-price auction).

Write A program This reads prices offered by bidders and finds the winner and the price he'll pay. Consider that all of the offered prices is different. Input

The first line of the input contains N (2≤n≤1000)-number of bidders. The second line contains n distinct integer numbers p1, p2, ... pn, separated by single spaces (1≤pi≤10000), where pi Stands for the price offered by the i-th bidder. Output

The single output line should contain, Integers:index of the winner and the price he'll pay. Indices is 1-based. Examples Input

2
5 7
Output
2 5
Input
3
10 2 8
Output
1 8
Input
6
3 8 2 9 4 14
Output
6 9

AC:

  #include <stdio.h> #include <string.h>
#include <algorithm>
using namespace std;
Int main ()
{
int n,i,m,j;
Int a[1005];
scanf ("%d", &n);
J=0;m=0;
for (i=0;i<n;i++)
{
scanf ("%d", &a[i]);
if (M<a[i])
{
M=a[i];
J=i;
}
}
Sort (a,a+n);
printf ("%d%d\n", ++j,a[n-2]);
return 0; 
}
 

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.