题目链接

https://vjudge.net/problem/CodeForces-1121C

题面

Description

Vasya likes taking part in Codeforces contests. When a round is over, Vasya follows all submissions in the system testing tab.

There are \(n\) solutions, the \(i\)-th of them should be tested on \(a_i\) tests, testing one solution on one test takes \(1\) second. The solutions are judged in the order from \(1\) to \(n\). There are \(k\) testing processes which test solutions simultaneously. Each of them can test at most one solution at a time.

At any time moment \(t\) when some testing process is not judging any solution, it takes the first solution from the queue and tests it on each test in increasing order of the test ids. Let this solution have id \(i\), then it is being tested on the first test from time moment \(t\) till time moment \(t + 1\), then on the second test till time moment \(t + 2\) and so on. This solution is fully tested at time moment \(t + a_i\), and after that the testing process immediately starts testing another solution.

Consider some time moment, let there be exactly \(m\) fully tested solutions by this moment. There is a caption "System testing: \(d\)%" on the page with solutions, where \(d\) is calculated as

\[d = round\left(100\cdot\frac{m}{n}\right),
\]

where \(round(x) = \lfloor{x + 0.5}\rfloor\) is a function which maps every real to the nearest integer.

Vasya calls a submission interesting if there is a time moment (possibly, non-integer) when the solution is being tested on some test \(q\), and the caption says "System testing: \(q\)%". Find the number of interesting solutions.

Please note that in case when multiple processes attempt to take the first submission from the queue at the same moment (for instance, at the initial moment), the order they take the solutions does not matter.

Input

The first line contains two positive integers \(n\) and \(k\) (\(1 \le n \le 1000\), \(1 \le k \le 100\)) standing for the number of submissions and the number of testing processes respectively.

The second line contains \(n\) positive integers \(a_1, a_2, \ldots, a_n\) (\(1 \le a_i \le 150\)), where \(a_i\) is equal to the number of tests the \(i\)-th submission is to be run on.

Output

Output the only integer — the number of interesting submissions.

Examples

Input

2 2
49 100

Output

1

Input

4 2
32 100 33 1

Output

2

Input

14 5
48 19 6 9 50 20 3 42 38 43 36 21 44 6

Output

5

Note

Consider the first example. At time moment \(0\) both solutions start testing. At time moment \(49\) the first solution is fully tested, so at time moment \(49.5\) the second solution is being tested on the test \(50\), and the caption says "System testing: \(50\)%" (because there is one fully tested solution out of two). So, the second solution is interesting.

Consider the second example. At time moment \(0\) the first and the second solutions start testing. At time moment \(32\) the first solution is fully tested, the third solution starts testing, the caption says "System testing: \(25\)%". At time moment \(32 + 24.5 = 56.5\) the third solutions is being tested on test \(25\), the caption is still the same, thus this solution is interesting. After that the third solution is fully tested at time moment \(32 + 33 = 65\), the fourth solution is fully tested at time moment \(65 + 1 = 66\). The captions becomes "System testing: \(75\)%", and at time moment \(74.5\) the second solution is being tested on test \(75\). So, this solution is also interesting. Overall, there are two interesting solutions.

题意

给定\(n\)个题目,每个题目有\(a[i]\)个测试点,有k台评测机,每台评测机在某一时刻只能测试一个题目,把所有测试点测完后测试队列中的下一道题,测试的进度用\(d = round\left(100\cdot\frac{m}{n}\right)\)来表示,其中\(round(x) = \lfloor{x + 0.5}\rfloor\) ,m是完全测完的题目数量,对于每一个测试中的题,如果某一时刻正好测试到\(i_{th}\)测试点,而\(i_{th}=d\)则这个题目被称为有趣的,问有多少有趣的题目

题解

我们可以用一个优先队列很快的算出每个题测试的开始时间和结束时间,然后我们就可以知道每个时刻前有多少个题目已经测试完毕了,所以就能算出每个时刻的测试进度,以及每个进度对应的时间区间,然后我们对于每一个题,遍历每一个时间进度覆盖的区间,如果和当前题结束和开始的时间段有交集就判断是否有趣。

至于如何判断,如果当前进度覆盖的区间刚好能包括进去当前题目的测试对应等于进度测试点的时间,那么就是有趣的,这个时间就是这个题目开始的时间+这个区间对应的进度值,,这个时间要大于等于这个进度的左端点,同时要小于等于这个题目测试完的时间和这个区间右端点的较小值。

AC代码

#include <bits/stdc++.h>
#define N 1050
using namespace std;
int a[N];
int min(int a, int b) {
return a < b ? a : b;
}
struct node {
int id, val;
node (int id = 0, int val = 0): id(id), val(val) {}
bool operator < (const node &b) const {
return val > b.val;
}
};
struct fin {
int l, r;
} finish[N];
int pre[150 * N];
int round1[150 * N];
struct pro{
int l; int r; int val;
} process[N];
priority_queue<node> q;
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= n; i++) {
if (q.size() < k) q.push(node(i, a[i]));
else {
node now = q.top();
finish[now.id].l = now.val - a[now.id];
finish[now.id].r = now.val;
q.pop();
q.push(node(i, a[i] + now.val));
}
}
int last = 0;
while (!q.empty()) {
node now = q.top();
finish[now.id].l = now.val - a[now.id];
finish[now.id].r = now.val;
last = max(last, now.val);
q.pop();
}
// for (int i = 1; i <= n; i++) {
// cout << finish[i].l << " " << finish[i].r << endl;
// }
for (int i = 1; i <= n; i++) {
pre[finish[i].r]++;
}
for (int i = 1; i <= last; i++) {
pre[i] += pre[i - 1];
}
for (int i = 1; i <= last; i++) {
round1[i] = floor((double)pre[i] / (double)n * 100 + 0.5);
}
int cnt = 0;
int tmp = 0;
for (int i = 1; i <= last; i++) {
if (round1[i] != round1[i - 1]) {
process[++cnt].val = round1[i];
process[cnt].l = i + 1;
if (cnt != 0) {
process[cnt - 1].r = i;
}
}
}
process[cnt].r = last + 1;
// for (int i = 1; i <= cnt; i++) {
// cout << process[i].l << " " << process[i].r << " " << process[i].val << endl;
// }
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= cnt; j++) {
if (process[j].l <= finish[i].r && process[j].r >= finish[i].l) {
if (process[j].l <= finish[i].l + process[j].val && min(finish[i].r, process[j].r) >= finish[i].l + process[j].val) {
// cout << "ans: " << i << endl;
ans++;
break;
}
}
}
}
printf("%d\n", ans);
return 0;
}

CodeForces-1121C System Testing的更多相关文章

  1. codeforces 22C System Administrator(构造水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud System Administrator Bob got a job as a s ...

  2. Codeforces 847H - Load Testing

    847H - Load Testing 思路:dp. 代码: #include<bits/stdc++.h> using namespace std; #define ll long lo ...

  3. codeforces Registration system

     Registration system A new e-mail service "Berlandesk" is going to be opened in Berland in ...

  4. Codeforces Rating System

    来翻译一下官方文档,但是建议看英文原文,本文可能会出现一些错误,虽然不是为了方便自己查阅用的. 首先,对于人 \(i\),定义 \(r_i\) 是他的 rating,对于人 \(i,j\),定义 \( ...

  5. CodeForces 22C System Administrator

    把v和2结点交换, 1和v连,其它点和v之间能够互相连. #include <iostream> #include <cstdlib> #include <cstring ...

  6. Difference between End-to-end testing and System testing

    www.guru99.com/end-to-end-testing.html

  7. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) A B C D 水 模拟 二分 贪心

    A. Is it rated? time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  8. Codeforces Round #412 (rated, Div. 2, base on VK Cup 2017 Round 3) D - Dynamic Problem Scoring

    地址:http://codeforces.com/contest/807/problem/D 题目: D. Dynamic Problem Scoring time limit per test 2 ...

  9. Codeforces Round #412 Div. 2 补题 D. Dynamic Problem Scoring

    D. Dynamic Problem Scoring time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. ListView与SimpleAdapter

    Adapter可以视作控件与数据之间的桥梁 对ListView做自由布局和填充需要使用到Adapter,这里我们采用SimpleAdapter. 简单来说: 1.定义一个ListItem,其数据结构是 ...

  2. Android学习笔记_49_Android中自定义属性(attrs.xml,TypedArray的使用)

    做Android布局是件很享受的事,这得益于他良好的xml方式.使用xml可以快速有效的为软件定义界面.可是有时候我们总感觉官方定义的一些基本组件不够用,自定义组件就不可避免了.那么如何才能做到像官方 ...

  3. JavaEE权限管理系统的搭建(七)--------管理用户的增删改

    本小结讲解管理用户的增删改查实现, 首先是添加用户,如下图所示,可以看到添加用户的同时也要给用户分配角色,至少给用户分配一个或者是多个角色 页面js部分: $.ajax({ //几个参数需要注意一下 ...

  4. c#中关于结构体和字节数组转化

    最近在使用结构体与字节数组转化来实现socket间数据传输.现在开始整理一下.对于Marshal可以查阅msdn,关于字节数组与结构体转代码如下: using System; using System ...

  5. JavaScript 表单处理

    表单对象的属性 name action method encoding target elements 表单对象的方法 submit reset 表单元素事件 文本域事件:onFocus(获得焦点) ...

  6. 关于alert后,才能继续执行后续代码问题

    如果在正常情况下,代码要在alert之后才执行,解决办法:将要执行的代码用setTimeout延迟执行即可(原因:页面未加载完毕) 首先,先说明问题情况: 如下JS代码,不能正常执行,只有在最前面加上 ...

  7. 什么是token及怎样生成token

    什么是token Token是服务端生成的一串字符串,以作客户端进行请求的一个令牌,当第一次登录后,服务器生成一个Token便将此Token返回给客户端,以后客户端只需带上这个Token前来请求数据即 ...

  8. 总结laravel假数据填充步骤

    定义好模型 xxx.php 定义好数据生成的规则 database/factories/XxxlFactory.php 写入生成数据的代码,控制好生成的数据数目,对生成后的数据做出修改 databas ...

  9. ruby Dir类

    类方法 1. Dir[pat]    Dir::glob( pat) 返回一个数组,包含与指定的通配符模式 pat 匹配的文件名: * - 匹配包含 null 字符串的任意字符串 ** - 递归地匹配 ...

  10. 文件 I/O字节流

    输入字节流: import java.io.*; public class test_main { public static void main(String[] args) { int n=-1; ...