CodeForces336 A & B

第一题就是排序然后计算一下时间。没什么

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package codeforces336;
 
import java.io.InputStreamReader;
import java.util.Scanner;
 
public class MainA {
    public static void sortArr(int[][] arr, int n) {
        int[] tmp = new int[2];
        for(int i = 0; i < n; ++i) {
            for(int j = i+1; j < n; ++j) {
                if(arr[i][0] < arr[j][0]) {
                    tmp[0] = arr[i][0];
                    tmp[1] = arr[i][1];
                    arr[i][0] = arr[j][0];
                    arr[i][1] = arr[j][1];
                    arr[j][0] = tmp[0];
                    arr[j][1] = tmp[1];
                }
            }
        }
    }
 
    public static void main(String[] args) {
        int n, s;
        int[][] arr = new int[105][2];
        Scanner sc = new Scanner(new InputStreamReader(System.in));
        n = sc.nextInt();
        s = sc.nextInt();
        for(int i = 0; i < n; ++i) {
            arr[i][0] = sc.nextInt();
            arr[i][1] = sc.nextInt();
        }
 
        sortArr(arr, n);
        int t = 0;
        int[] tmp = new int[2];
        for(int i = 0; i < n; ++i) {
            tmp[0] = s - arr[i][0];
            tmp[1] = arr[i][1];
            if(tmp[1] < (t + tmp[0])){
                t += tmp[0];
            } else {
                t = tmp[1];
            }
            s = arr[i][0];
        }
        if(s != 0) {
            t += s;
        }
        System.out.println(t);
    }
}

 第二题,暴力肯定TLE,用前缀和算可以。看a的每一位,是0,统计在 lenb - lena + i  ~ i - 1 范围内 1的 个数;是 1,统计在 lenb - lena + i  ~ i - 1 范围内 0 的 个数

 

posted @   unicoe  阅读(265)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示