QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#298798#6250. کلاس طراحی الگوریتم‌هاmahdimalverdiWA 158ms61096kbJava111.9kb2024-01-06 14:49:592024-01-06 14:50:00

Judging History

你现在查看的是最新测评结果

  • [2024-01-06 14:50:00]
  • 评测
  • 测评结果:WA
  • 用时:158ms
  • 内存:61096kb
  • [2024-01-06 14:49:59]
  • 提交

answer

import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

class Codechef {
    public static void main(String[] args) throws java.lang.Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long[] nums1 = new long[n];
        long[] nums2 = new long[n];

        for (int i = 0; i < n; i++) {
            nums1[i] = sc.nextLong();
        }
        for (int i = 0; i < n; i++) {
            nums2[i] = sc.nextLong();
        }

        PriorityQueue<Student> s1 = new PriorityQueue<>(Comparator.comparing(l -> l.num1 * -1));

        for (int i = 0; i < n; i++) {
            Student student = new Student(nums1[i], nums2[i]);
            s1.add(student);
        }
        long sum = 0;

        Student student = s1.poll();
        while (!s1.isEmpty()) {
            Student student1 = s1.poll();
            Student student2 = s1.poll();

            PriorityQueue<Student> s2 = new PriorityQueue<>(Comparator.comparing(l -> l.num2 * -1));

            s2.add(student1);
            if(student2 != null){
                s2.add(student2);
            }

            while (!s1.isEmpty() && student2 != null && student1.num1 == student2.num1){
                student1 = s1.poll();
                student2 = s1.poll();

                s2.add(student1);
                if(student2 != null){
                    s2.add(student2);
                }
            }

            final int size = s2.size();

            for(int i =0;i<size/2.0;i++ ){
                sum += s2.poll().num2;
            }
        }

        System.out.println(sum);
    }

    public static class Student {
        public Long num1;
        public Long num2;
        public Boolean visited;

        public Student(long num1, long num2) {
            visited = false;
            this.num1 = num1;
            this.num2 = num2;
        }
    }
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 100ms
memory: 53620kb

input:

3
1 8 4
12 11 1

output:

12

result:

ok single line: '12'

Test #2:

score: 0
Accepted
time: 98ms
memory: 53544kb

input:

5
1 2 3 4 5
2 3 4 5 6

output:

8

result:

ok single line: '8'

Test #3:

score: -100
Wrong Answer
time: 158ms
memory: 61096kb

input:

1180
961126767 261224755 907153108 798212484 599761097 743695587 995677693 496776751 924069769 564704455 429970021 140904220 294673948 518226561 354056387 468468805 420623399 648026114 519204933 451212087 891148030 391954964 211868427 570192789 268490285 866150098 808117417 634459540 981698547 75398...

output:

396052116902

result:

wrong answer 1st lines differ - expected: '444484036729', found: '396052116902'