QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406165#6525. New HousesChongQYWA 573ms193228kbJava84.5kb2024-05-06 21:31:582024-05-06 21:31:59

Judging History

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

  • [2024-05-06 21:31:59]
  • 评测
  • 测评结果:WA
  • 用时:573ms
  • 内存:193228kb
  • [2024-05-06 21:31:58]
  • 提交

answer

import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;

public class Main {
    public static Read scanner = new Read(System.in);
    public static final long MOD = (long) (1e9 + 7);
    public static final int MID = (int) (5 * 1e5 + 7);
    public static final long LMAX = Long.MAX_VALUE;
    public static final long LMIN = Long.MIN_VALUE;
    public static final int IMAX = Integer.MAX_VALUE;
    public static final int IMIN = Integer.MIN_VALUE;
    public static way[] arr = new way[MID];
    //    public static long[] Qz = new long[MID];
//    public static long[] Hz = new long[MID];
    public static int N, M , n , m;
    public static long ans;
//    public static boolean[][] stack = new boolean[MID][MID];

    //四个方向
    public static int[] row = {1, -1, 0, 0};
    public static int[] cos = {0, 0, 1, -1};
    static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static void solve(){
        int n = scanner.nextInt();//人
        int m = scanner.nextInt();//屋子
        long t = m - n;//空着的房子
        ans = 0;
        for(int i = 1 ; i <= n ; i++){
            long a = scanner.nextLong();
            long b = scanner.nextLong();
            arr[i] = new way(a , b);
            ans += b;
        }
        if(t == 0){
            ans = 0;
            for(int i = 1 ; i <= n ; i++) ans += arr[i].x;
            out.println(ans);
            return;
        }
        Arrays.sort(arr, 1, n + 1, new Comparator<way>() {
            @Override
            public int compare(way o1, way o2) {
                return Long.compare(o2.x - o2.y , o1.x - o1.y);
            }
        });
        int o = 0;
        for(int i = 1 ; i <= n ; i++) if(arr[i].x > arr[i].y) o++;
        if(o > 1)
            for(int i = 1 ; i <= n ; i++){
                if(t == 0) break;
                if(arr[i].x - arr[i].y > 0){
                    ans += arr[i].x - arr[i].y;
                } else {
                    if(t >= n - i + 1) break;
                    ans += arr[i].x - arr[i].y;
                }
            }
        out.println(ans);


/*
3
4 5
1 100
100 1
100 1
100 1
2 2
1 10
1 10
2 3
100 50
1 1000
 */






    }

    public static void main(String[] args) {

//        long start = System.currentTimeMillis();//程序开始时间戳
        int T = scanner.nextInt();
        while (T-- != 0) {
            solve();
        }
        out.flush();
//        long end = System.currentTimeMillis();//程序结束时间戳
//        out.println("运行时间 : " + (end - start));//输出运行时间
    }

    //快读
    static class Read {
        BufferedReader br;
        StringTokenizer st;

        public Read(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in), 16384);
            eat("");
        }

        public void eat(String s) {
            st = new StringTokenizer(s);
        }

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public boolean hasNext() {
            while (!st.hasMoreTokens()) {
                String s = nextLine();
                if (s == null)
                    return false;
                eat(s);
            }
            return true;
        }

        public String next() {
            hasNext();
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public Double nextDouble() {
            return Double.parseDouble(next());
        }

        public BigInteger nextBigInteger() {
            return new BigInteger(next());
        }

        public BigDecimal nextBigDecimal() {
            return new BigDecimal(next());
        }
    }
    public static void swap(long[] arr , int index1 , int index2){
        long t = arr[index1];
        arr[index1] = arr[index2];
        arr[index2] = t;
    }
    public static long Dot_pitch(long x , long y , long xx , long yy){
        return (xx - x) * (xx - x) + (yy - y) * (yy - y);
//        return (long) Math.sqrt(Math.pow(xx - x , 2) + Math.pow(yy - y , 2));
    }
}

class way {
    public long x , y;

    public way(long x, long y) {
        this.x = x;
        this.y = y;
    }
}

詳細信息

Test #1:

score: 100
Accepted
time: 41ms
memory: 44384kb

input:

3
4 5
1 100
100 1
100 1
100 1
2 2
1 10
1 10
2 3
100 50
1 1000

output:

400
2
1050

result:

ok 3 number(s): "400 2 1050"

Test #2:

score: -100
Wrong Answer
time: 573ms
memory: 193228kb

input:

100000
6 11
191141536 365120521
799679686 648574232
102602909 467685128
405440859 796808887
384858152 191995380
433392826 195648471
5 13
831367906 510447872
795639287 575551283
811207605 176441088
240156289 946977042
133416463 721098873
5 5
806744021 699586200
630510306 637827160
49223781 641709297
...

output:

3247545200
4106290713
2653993029
5122532137
5570513606
2031887824
2044500908
1345295010
6815058419
2237593918
6646615756
5638337819
3690874076
5497726904
5513905900
5404435094
4705403467
2411992217
3430587752
5098767681
3921151709
1271949960
2692878616
3833748807
2409784919
850381192
6464787173
8839...

result:

wrong answer 8th numbers differ - expected: '1857678917', found: '1345295010'