From f124feefd814ff19d8cc344a836127f3ce4f738f Mon Sep 17 00:00:00 2001 From: "huangge1199@hotmail.com" Date: Sun, 29 Aug 2021 15:51:48 +0800 Subject: [PATCH] =?UTF-8?q?meituan-011.=20=E6=90=AD=E9=85=8D=E5=87=BA?= =?UTF-8?q?=E5=94=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plan/meituan/meituan011/Solution.java | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 src/main/java/study/plan/meituan/meituan011/Solution.java diff --git a/src/main/java/study/plan/meituan/meituan011/Solution.java b/src/main/java/study/plan/meituan/meituan011/Solution.java new file mode 100644 index 0000000..1afb747 --- /dev/null +++ b/src/main/java/study/plan/meituan/meituan011/Solution.java @@ -0,0 +1,90 @@ +package study.plan.meituan.meituan011; + +import java.io.*; +import java.util.StringTokenizer; + +class Solution { + + static Scanner sc; + static PrintWriter pw; + + public static void main(String[] args) throws IOException { + sc = new Scanner(System.in); + pw = new PrintWriter(System.out); + solve(); + pw.close(); + } + + public static void solve() throws IOException { + int[] counts = sc.nextIntArr(4); + int[] prices = sc.nextIntArr(3); + int max = 0; + int min = 0; + for (int i = 1; i < 3; i++) { + if (prices[i] > prices[max]) { + max = i; + } else if (prices[i] < prices[min]) { + min = i; + } + } + int mid = 0; + for (int i = 0; i < 3; i++) { + if (i != max && i != min) { + mid = i; + } + } + int count = Math.min(counts[max], counts[3]); + long sum = (long) count * prices[max]; + counts[3] -= count; + if (counts[3] > 0) { + count = Math.min(counts[mid], counts[3]); + sum += (long) count * prices[mid]; + } + counts[3] -= count; + if (counts[3] > 0) { + count = Math.min(counts[min], counts[3]); + sum += (long) count * prices[min]; + } + pw.println(sum); + } + + static class Scanner { + BufferedReader br; + StringTokenizer st; + + public Scanner(InputStream s) { + br = new BufferedReader(new InputStreamReader(s)); + } + + public Scanner(FileReader f) { + br = new BufferedReader(f); + } + + public String next() throws IOException { + while (st == null || !st.hasMoreTokens()) + st = new StringTokenizer(br.readLine()); + return st.nextToken(); + } + + public int nextInt() throws IOException { + return Integer.parseInt(next()); + } + + public long nextLong() throws IOException { + return Long.parseLong(next()); + } + + public double nextDouble() throws IOException { + return Double.parseDouble(next()); + } + + public int[] nextIntArr(int n) throws IOException { + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = Integer.parseInt(next()); + } + return arr; + } + + } +}