0Dima_0

вош 2021 2

Oct 27th, 2021
831
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. class Main {
  4.   public static void main(String[] args) {
  5.     Scanner s = new Scanner(System.in);
  6.     int a = s.nextInt();
  7.     int b = s.nextInt();
  8.     int c = s.nextInt();
  9.     long n = s.nextLong();
  10.     int last = s.nextInt();
  11.     long spent = 0;
  12.     spent = (n / 3) * (a + b + c);
  13.     if(n % 3 != 0){
  14.       if(last == 1) spent += a;
  15.       else if(last == 2) spent += b;
  16.       else if(last == 3) spent += c;
  17.       for(int i = 0; i < n % 3 - 1; i++){
  18.         if(last == 1){
  19.           spent += b;
  20.           last = 2;
  21.         }
  22.         else if(last == 2){
  23.           spent += c;
  24.           last = 3;
  25.         }
  26.         else if(last == 3){
  27.           spent += a;
  28.           last = 1;
  29.         }
  30.       }
  31.     }
  32.     System.out.print(spent);
  33.   }
  34. }
RAW Paste Data