- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# C++ Program to find winner and final price in a second price auction event

Suppose we have an array A with n elements. There is a special type of an auction, which is called the second-price auction. In a regular auction, n bidders place a bid which is price a bidder ready to pay. The auction ends, when each bidder secretly informs the organizer of the auction price he is willing to pay. After that, the auction winner is the participant who offered the highest price. But here, he pay not the price he offers, but the highest price among the offers of other participants (the second-price auction). A[i] is the price offered by ith bidder. We have to find the winner and the price he will pay. All of the offered prices are unique.

## Problem Category

An array in the data structure is a finite collection of elements of a specific type. Arrays are used to store elements of the same type in consecutive memory locations. An array is assigned a particular name and it is referenced through that name in various programming languages. To access the elements of an array, indexing is required. We use the terminology 'name[i]' to access a particular element residing in position 'i' in the array 'name'. Various data structures such as stacks, queues, heaps, priority queues can be implemented using arrays. Operations on arrays include insertion, deletion, updating, traversal, searching, and sorting operations. Visit the link below for further reading.

https://www.tutorialspoint.com/data_structures_algorithms/array_data_structure.htm

So, if the input of our problem is like A = [3, 8, 2, 9, 4, 14], then the output will be 5, 9, because the winner is at index 5 with prices offered 14, and he will pay 9.

## Steps

To solve this, we will follow these steps −

n := size of A i := index of the maximum element in A sort the array A l := A[n - 2] print i and l

## Example

Let us see the following implementation to get better understanding −

#include <bits/stdc++.h> using namespace std; void solve(vector<int> A){ int n = A.size(); int i = max_element(A.begin(), A.end()) - A.begin(); sort(A.begin(), A.end()); int l = A[n - 2]; cout << i << ", " << l; } int main(){ vector<int> A = { 3, 8, 2, 9, 4, 14 }; solve(A); }

## Input

{ 3, 8, 2, 9, 4, 14 }

## Output

5, 9

- Related Articles
- C++ Program to find out the total price
- Find cost price from given selling price and profit or loss percentage in C++
- Compare bid price and offer price
- If Selling price $=$ S.P, Discount % $=$ D, find cost price.
- The price of a chair is reduced by 25%. What is the ratio of(i) Change in price to the old price(ii) Old price to the new price
- Find Selling Price from given Profit Percentage and Cost in C++
- Find the marked price(MP), when (selling price)SP$=$â‚¹5600 and discount $=$â‚¹990.
- If cost price = Rs 400 and selling price = Rs 500, profit% =
- If cost price = Rs 600 and loss = 60, then selling price =
- If the selling price of a bike is â‚¹19000 and the profit gained is 7% find the cost price.
- Python Program to find out the price of a product after a number of days
- Program to find maximum price we can get by holding items into a bag in Python
- Price Psychology in Marketing
- If Marked Price = 400â‚¹ and Selling Price =300â‚¹ , then what is the discount percentage ?
- Filter Restaurants by Vegan-Friendly, Price and Distance in C++