Advertisement
Guest User

Untitled

a guest
May 18th, 2021
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.91 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3. import java.math.*;
  4.  
  5. /**
  6.  * Auto-generated code below aims at helping you parse
  7.  * the standard input according to the problem statement.
  8.  **/
  9. class Solution {
  10.  
  11.     public static void main(String args[]) {
  12.         Scanner in = new Scanner(System.in);
  13.         int seats = in.nextInt();
  14.         int rides = in.nextInt();
  15.         int groups = in.nextInt();
  16.         List<Integer> queue = new ArrayList<>();
  17.         Map<String,Integer> pplInCart=new LinkedHashMap<>();
  18.         for (int i = 0; i < groups; i++) {
  19.             queue.add(in.nextInt());
  20.         }
  21.         long earnings=0;
  22.         String ride;
  23.         int pos = 0,startPos;
  24.         int tot;
  25.         for (int i = 0; i < rides; i++) {
  26.             tot=0;
  27.             startPos=pos;
  28.             ride="";
  29.             while(tot<seats){
  30.                 tot+=queue.get(pos);
  31.                 if (tot<=seats){
  32.                     ride+=pos+",";
  33.                     pos++;
  34.                     if (pos==groups)
  35.                         pos=0;
  36.                     if (pos==startPos)
  37.                         break;
  38.                 }else{
  39.                     tot-=queue.get(pos);
  40.                     break;
  41.                 }
  42.             }
  43.             if (pplInCart.containsKey(ride)){
  44.                 break;
  45.             }
  46.             pplInCart.put(ride, tot);
  47.         }
  48.         pos=0;
  49.         List<Integer> values = new ArrayList<>(pplInCart.values());
  50.         int max = values.size();
  51.         int aux=0;
  52.         for (String s : pplInCart.keySet()) {
  53.             aux+=1;
  54.         }
  55.         for (int i = 0; i < rides; i++) {
  56.             earnings+=values.get(pos);
  57.             pos+=1;
  58.             if (pos==max)
  59.                 pos=0;
  60.         }
  61.         // Write an answer using System.out.println()
  62.         // To debug: System.err.println("Debug messages...");
  63.         System.out.println(earnings);
  64.     }
  65. }//89738136800958
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement