Official

A - Order Something Else Editorial by en_translator


For beginners
  • If you are new to learning programming and do not know where to start, please try Problem A "Welcome to AtCoder" from practice contest. There you can find a sample code for each language.
  • Also, if you are not familiar with problems in programming contests, we recommend you to try some problems in "AtCoder Beginners Selection".
  • 競プロ典型 90 問」(Typical 90 Problems of Competitive Programming) is a collection of typical 90 competitive programming problems; unfortunately, currently the problem statements are all Japanese.
  • C++入門 AtCoder Programming Guide for beginners (APG4b)」 is a C++ tutorial for competitive programmers. Sadly, this is only in Japanese too.

If you use a coupon, it is optimal to order the cheapest dish. Thus, it is sufficient to compute

  • the price when the coupon is not used (\(P\) yen) and
  • the price when the coupon is used, and the cheapest dish is ordered (let this be \(D_{\min}\) yen),

and print the cheapest among them, \(\min\lbrace P, Q + D_{\min}\rbrace\).

To find the price of the cheapest dish \(D_{\min}\), you need to inspect all the dishes \(1, 2, \ldots, N\) in order, and compare their prices. One can “inspect dishes \(1, 2, \ldots, N\) in order” with the loop feature (like the for statement), which is a standard feature of a programming language.

The following is an example of accepted code for this problem in C++ language.

#include <iostream>
using namespace std;

int main(void)
{
  int n, p, q;
  cin >> n >> p >> q;
  
  int d_min = 1000000000, d;
  for(int i = 1; i <= n; i++){
    cin >> d;
    d_min = min(d, d_min);
  }
  cout << min(p, q+d_min) << endl;
  
  return 0;
}    

posted:
last update: