本文主要是介绍CF 508C,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
点击打开链接
import java.util.Arrays;
import java.util.Scanner;public class Main {public static void main(String [] args){new Solve().run() ;}
}class Solve{int bit[] = new int[608] ;int lowbit(int x){return x & (-x) ;}int sum(int i){int s = 0 ; for(int j = i ; j > 0 ; j -= lowbit(j)) s += bit[j] ;return s ;}void insert(int i , int d){for(int j = i ; j < 608 ; j += lowbit(j)) bit[j] += d ;}int []c = new int[308] ;void run(){Scanner cin = new Scanner(System.in) ;Arrays.fill(bit, 0) ; int n = cin.nextInt() ;int t = cin.nextInt() ;int r = cin.nextInt() ;for(int i = 0 ; i < n ; i++){c[i] = 300 + cin.nextInt() ;}if(t < r){System.out.println("-1") ;return ;}int g , need = 0 , ans = 0 ;for(int i = 0 ; i < n ; i++){g = sum(c[i]) ;if(g < r){need = r - g ;ans += need ;for(int j = c[i] - need ; j < c[i] ; j++){insert(j, 1);insert(j + t + 1 , -1) ;}}}System.out.println(ans) ;}}
这篇关于CF 508C的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!