1 solutions
-
0
C++ :
#include<iostream> using namespace std; int main(){ const int penKinds = 3; int penAmount,penPrice; int minCost = 0; int n; cin>>n; for(int i = 0;i < penKinds;i++){ cin>>penAmount>>penPrice; int penCost = (n/penAmount)*penPrice; if(n%penAmount != 0) penCost += penPrice; if(i == 0 || (i != 0 && penCost < minCost)) minCost = penCost; } cout<<minCost; return 0; }
Java :
import java.util.Scanner; import java.util.Arrays; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); int a1 = scan.nextInt(); int a2 = scan.nextInt(); int b1 = scan.nextInt(); int b2 = scan.nextInt(); int c1 = scan.nextInt(); int c2 = scan.nextInt(); int pen1 = 0, pen2 = 0, pen3 = 0; int[] array = new int[4]; while(pen1 < n){ pen1 = pen1 + a1; array[0] = array[0] + a2; } while(pen2 < n){ pen2 = pen2 + b1; array[1] = array[1] + b2; } while(pen3 < n){ pen3 = pen3 + c1; array[3] = array[3] + c2; } Arrays.sort(array); System.out.println(array[1]); } }
- 1
Information
- ID
- 9197
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- (None)
- Tags
- # Submissions
- 0
- Accepted
- 0
- Uploaded By