Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RadioGaGa{
- private static Scanner scan = new Scanner(System.in);
- private static int n = scan.nextInt();
- private static List<Song> songs = new ArrayList<Song>();
- private static int time;
- private static double weight;
- private static int days;
- private static int timeS;
- private static int D;
- private static SongComparator comparator = new SongComparator();
- private static void populate(){
- for(int i = 0; i < n; i++){
- String name = scan.next();
- int len = scan.nextInt();
- double pop = scan.nextDouble();
- Song song = new Song(name, len, pop);
- songs.add(song);
- }
- Collections.sort(songs, comparator);
- time = scan.nextInt();
- weight = scan.nextDouble();
- days = scan.nextInt();
- timeS = time * 60;
- }
- private static String day0(){
- int pLen = 0;
- String result = "";
- List<Song> zero = new ArrayList<>();
- for(int i = 0; i < n; i++){
- if(pLen + songs.get(i).getLen() < timeS){
- pLen = pLen + songs.get(i).getLen();
- zero.add(songs.get(i));
- }
- }
- for(Song song : zero){
- result += " " + song.getName();
- }
- return D + result;
- }
- private static String dayN(int D){
- int pLen = 0;
- List<Song> playlist = new ArrayList<>();
- String result = "";
- int requests = scan.nextInt();
- for(int i = 0; i < requests; i++){
- String rName = scan.next();
- for (Song song : songs) {
- if (song.getName().equals(rName)) {
- song.setPop(weight, D);
- }
- }
- }
- Collections.sort(songs, comparator);
- for(int i = 0; i < n; i++){
- if(pLen + songs.get(i).getLen() < timeS){
- pLen = pLen + songs.get(i).getLen();
- playlist.add(songs.get(i));
- }
- }
- for(Song song : playlist){
- result += " " +song.getName();
- }
- return D + result;
- }
- public static void main(String[] args){
- populate();
- System.out.println(day0());
- for(int i = 1; i <= days; i++){
- System.out.println(dayN(i));
- }
- }
- }
- public class Song {
- private String name;
- private int len;
- private double pop;
- Song(String name, int len, double pop){
- this.name = name;
- this.len = len;
- this.pop = pop;
- }
- public int getLen(){
- return this.len;
- }
- public String getName(){
- return this.name;
- }
- public double getPop(){
- return this.pop;
- }
- public void setPop(double pop, int D){
- this.pop = pop + pop;
- }
- public String toString(){
- return name;
- }
- }
- import java.util.Comparator;
- public class SongComparator implements Comparator<Song> {
- private enum Order {pop, len}
- private Order sortingBy = Order.pop;
- SongComparator(){
- }
- public int compare(Song s1, Song s2) {
- if(s1.getPop() == s2.getPop()){
- if(s1.getLen() < s2.getLen()){
- return -1;
- }else if(s1.getLen() > s2.getLen()){
- return 1;
- }else{
- return 0;
- }
- }
- if(s1.getPop() < s2.getPop()){
- return 1;
- }else{
- return -1;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement