Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- import java.math.*;
- /**
- * Auto-generated code below aims at helping you parse
- * the standard input according to the problem statement.
- **/
- class Solution {
- public static void main(String args[]) {
- Scanner in = new Scanner(System.in);
- int seats = in.nextInt();
- int rides = in.nextInt();
- int groups = in.nextInt();
- List<Integer> queue = new ArrayList<>();
- Map<String,Integer> pplInCart=new LinkedHashMap<>();
- for (int i = 0; i < groups; i++) {
- queue.add(in.nextInt());
- }
- long earnings=0;
- String ride;
- int pos = 0,startPos;
- int tot;
- for (int i = 0; i < rides; i++) {
- tot=0;
- startPos=pos;
- ride="";
- while(tot<seats){
- tot+=queue.get(pos);
- if (tot<=seats){
- ride+=pos+",";
- pos++;
- if (pos==groups)
- pos=0;
- if (pos==startPos)
- break;
- }else{
- tot-=queue.get(pos);
- break;
- }
- }
- if (pplInCart.containsKey(ride)){
- break;
- }
- pplInCart.put(ride, tot);
- }
- pos=0;
- List<Integer> values = new ArrayList<>(pplInCart.values());
- int max = values.size();
- int aux=0;
- for (String s : pplInCart.keySet()) {
- aux+=1;
- }
- for (int i = 0; i < rides; i++) {
- earnings+=values.get(pos);
- pos+=1;
- if (pos==max)
- pos=0;
- }
- // Write an answer using System.out.println()
- // To debug: System.err.println("Debug messages...");
- System.out.println(earnings);
- }
- }//89738136800958
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement