Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Main {
- public static void main(String[] args) {
- Scanner s = new Scanner(System.in);
- int a = s.nextInt();
- int b = s.nextInt();
- int c = s.nextInt();
- long n = s.nextLong();
- int last = s.nextInt();
- long spent = 0;
- spent = (n / 3) * (a + b + c);
- if(n % 3 != 0){
- if(last == 1) spent += a;
- else if(last == 2) spent += b;
- else if(last == 3) spent += c;
- for(int i = 0; i < n % 3 - 1; i++){
- if(last == 1){
- spent += b;
- last = 2;
- }
- else if(last == 2){
- spent += c;
- last = 3;
- }
- else if(last == 3){
- spent += a;
- last = 1;
- }
- }
- }
- System.out.print(spent);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement