Find the answer

Time Limit: 4000/4000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0

Problem Description

Given a sequence of n integers called W and an integer m. For each i (1 <= i <= n), you can choose some elements W**k (1 <= k < i), and change them to zero to make ∑i**j=1W**j<=m. So what's the minimum number of chosen elements to meet the requirements above?.

Input

The first line contains an integer Q --- the number of test cases.

For each test case:

The first line contains two integers n and m --- n represents the number of elemens in sequence W and m is as described above.

The second line contains n integers, which means the sequence W.

1 <= Q <= 15

1 <= n <= 2*105

1 <= m <= 109

For each i, 1 <= W**i <= m

Output

For each test case, you should output n integers in one line: i-th integer means the minimum number of chosen elements W**k (1 <= k < i), and change them to zero to make ∑i**j=1W**j<=m.

Sample Input

2
7 15
1 2 3 4 5 6 7
5 100
80 40 40 40 60

Sample Output

0 0 0 0 0 2 3
0 1 1 2 3

题意

自己读题,几句话很难说清楚

转化一下就是将最少的数变成0,并且自己不能选,使\(\sum_{j=1}^{i} \leq m\),输出最小的次数。

题解

贪心一下,取最大的几个。

离散+权值线段树就成。

代码

#include<bits/stdc++.h>
#define int long long
#define DEBUG cerr << "Call out: " << __func__ << "\t" << "Line: " << __LINE__ << "\t :"
using namespace std;
#define MAXN 200010
struct sgt
{
int val,p;
int l,r;
} f[MAXN<<2]; int wh[MAXN];
int a[MAXN];
pair <int,int> pt[MAXN];
int n;
int m; void build(int x,int l,int r)
{
f[x].l = l;
f[x].r = r;
f[x].val = f[x].p = 0;
if (l == r) return;
build(x<<1,l,(l+r)>>1);
build(x<<1|1,((l+r)>>1)+1,r);
} void add(int x,int pos,int val)
{
f[x].val += val;
f[x].p ++;
if (f[x].l == pos && f[x].r == pos) return;
if (pos > f[x<<1].r) add(x<<1|1,pos,val);
else add(x<<1,pos,val);
} int query(int x,int val)
{
if (f[x].l == f[x].r)
if (f[x].val == val) return f[x].p;
else return 0;
if (f[x<<1].val >= val) return query(x<<1,val);
return f[x<<1].p + query(x<<1|1,val - f[x<<1].val);
} signed main()
{
int T;
cin >> T;
while (T--)
{
cin >> n >> m;
memset(f,0,sizeof(f));
build(1,1,n);
for (int i=1; i<=n; i++)
scanf("%d",a+i),pt[i].first = a[i], pt[i].second = i;
sort(pt+1,pt+n+1);
for (int i=1; i<=n; i++)
wh[pt[i].second] = i;
int tot = 0;
for (int i=1; i<=n; i++)
{
tot += a[i];
if (tot <= m) printf("0 ");
if (tot > m) printf("%d ",i-query(1,m-a[i])-1);
add(1,wh[i],a[i]);
}
puts("");
}
}

2019 Multi-University Training Contest 3 T7 Find the answer的更多相关文章

  1. 2019 Nowcoder Multi-University Training Contest 4 E Explorer

    线段树分治. 把size看成时间,相当于时间 $l$ 加入这条边,时间 $r+1$ 删除这条边. 注意把左右端点的关系. #include <bits/stdc++.h> ; int X[ ...

  2. 2019 Nowcoder Multi-University Training Contest 1 H-XOR

    由于每个元素贡献是线性的,那么等价于求每个元素出现在多少个异或和为$0$的子集内.因为是任意元素可以去异或,那么自然想到线性基.先对整个集合A求一遍线性基,设为$R$,假设$R$中元素个数为$r$,那 ...

  3. 2019 Multi-University Training Contest 8

    2019 Multi-University Training Contest 8 C. Acesrc and Good Numbers 题意 \(f(d,n)\) 表示 1 到 n 中,d 出现的次数 ...

  4. 2019 Multi-University Training Contest 7

    2019 Multi-University Training Contest 7 A. A + B = C 题意 给出 \(a,b,c\) 解方程 \(a10^x+b10^y=c10^z\). tri ...

  5. 2019 Multi-University Training Contest 1

    2019 Multi-University Training Contest 1 A. Blank upsolved by F0_0H 题意 给序列染色,使得 \([l_i,r_i]\) 区间内恰出现 ...

  6. 2019 Multi-University Training Contest 2

    2019 Multi-University Training Contest 2 A. Another Chess Problem B. Beauty Of Unimodal Sequence 题意 ...

  7. 2019 Multi-University Training Contest 5

    2019 Multi-University Training Contest 5 A. fraction upsolved 题意 输入 \(x,p\),输出最小的 \(b\) 使得 \(bx\%p&l ...

  8. HDU校赛 | 2019 Multi-University Training Contest 6

    2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...

  9. HDU校赛 | 2019 Multi-University Training Contest 5

    2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...

随机推荐

  1. 【Angular5】 返回前一页面 go back to previous page

    import { Component, OnInit } from '@angular/core'; import { Router} from '@angular/router'; import { ...

  2. qs.js使用方法

    https://github.com/ljharb/qs 占个空

  3. [转帖]yum 下载rpm包 之前不知道具体的存放路径.

    使用Yum下载RPM包-进击的二狗子-51CTO博客 https://www.2cto.com/os/201905/807225.html yumdownloader 命令 yum install y ...

  4. 【转帖】Linux系统上面qemu 模拟arm

    零基础在Linux系统搭建Qemu模拟arm https://blog.csdn.net/weixin_42489042/article/details/81145038 自己没搞定 改天再试试 感谢 ...

  5. c++ vector 使用注意事项

    1. 初始化 c++ 11以后新增了大括号{}的初始化方式,需要注意与()的区别,如: std::vector<int> vecTest1(5);         //初始化5个元素,每个 ...

  6. 怎么编写properties文件

    1. 注释 在properties中注释是采用#号开头的方式来进行注释的 2. 编写properties文件 在properties中,一行就是一个键值对,简单的理解就是一行可以保存一个变量,键和值之 ...

  7. 从入门到自闭之python初识

    Day 01 整型: 对比: 在python 2 版本中有整型,长整型long 在python 3 版本中全部都是整型 用于计算和比较 整型和布尔值的转换 二进制转换成十进制: ​print (int ...

  8. os.path路径拓展 python3

    os.path-对路径path进行的操作 在调用os.path时, 根据操作系统的不同 程序会选择使用posixpath.py或ntpath.py(由os中的代码实现). 对文件命名时应当使用unic ...

  9. PythonDay14

    第十四章装饰器 装饰器 # 开放封闭原则- 1.对扩展是开放的- 2.对修改是封闭的​# 在不修改源代码和调用方式的情况下,对函数进行扩展# 第一版装饰器def times(func):    def ...

  10. linux查看网络ip得两个命令ifconfig和 ip addr

    在安装linux 得时候,我们要选择桥接网络,相当于本电脑和虚拟机得电话都是接通外网,linux查看网络ip得两个命令ifconfig和 ip addr 1,命令ifconfig 如果ifconfig ...