# 163 条题解

• @ 2020-07-17 15:22:02
``````#include<bits/stdc++.h>
typedef unsigned long long ull;
using namespace std;
int n,cnt,m,a[10000000];
struct s{
int tz,bh,pg=0;
}b[10000000];
bool cmp(s a,s b){
return a.tz>b.tz;
}
bool cmp2(s a,s b){
return a.bh<b.bh;
}
int main(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int j=1;j<=m;j++) cin>>b[j].tz,b[j].bh=j;
sort(a+1,a+n+1);
sort(b+1,b+n+1,cmp);
n++;
int i=1,l=n;
while(n--){
if(i==m+1) i=1;
b[i].pg+=a[n];
i++;
}
sort(b+1,b+m+1,cmp2);
for(int i=1;i<=m;i++) cout<<b[i].pg<<' ';
}

``````
• @ 2021-01-07 22:55:30
``````#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;

namespace dts
{
typedef long long ll;
const ll sz=1<<17;
class tt{
public:
ll t,num,ans=0;
};
int cmp_less(ll a,ll b)
{
return a<b;
}
int cmp_greater(ll a,ll b)
{
return a>b;
}
ll n,m,a[sz],ans[sz];
tt rec[sz];
int cmptt(tt a,tt b)
{
return a.t>b.t;
}
void main()
{
scanf("%lld%lld",&n,&m);
for (ll i=0;i<n;i++)
scanf("%lld",&a[i]);
for (ll i=0;i<m;i++)
scanf("%lld",&rec[i].t),rec[i].num=i,rec[i].ans=0;
sort(&a[0],&a[n],cmp_greater);
sort(&rec[0],&rec[m],cmptt);
for (ll i=0,j=0;j<n;i=(i+1)%m,j++)
rec[i].ans+=a[j];
memset(ans,0,sizeof(ans));
for (ll i=0;i<m;i++)
ans[rec[i].num]=rec[i].ans;
for (ll i=0;i<m;i++)
printf("%lld ",ans[i]);
printf("\n");
}
};

int main()
{
dts::main();
}
``````
• @ 2019-08-04 13:11:24

暴力排序居然过了

``````#include <iostream>
#include <algorithm>

using namespace std;

typedef struct
{
int no;
int w;
int acc=0;
}tt;

int n,m;
int apple[100000];
tt tlist[100000];

bool compt(tt a,tt b)
{
return a.w>b.w;
}

bool compre(tt a,tt b)
{
return a.no<b.no;
}

bool compa(int a,int b)
{
return a>b;
}

int main()
{
cin>>n>>m;
int i;
for(i=0;i<n;i++)
{
cin>>apple[i];
}
for(i=0;i<m;i++)
{
cin>>tlist[i].w;
tlist[i].no=i;
}
sort(apple,apple+n,compa);
sort(tlist,tlist+m,compt);
for(i=0;i<n;i++)
{
tlist[i%m].acc+=apple[i];
}
sort(tlist,tlist+m,compre);
for(i=0;i<m;i++)
{
cout<<tlist[i].acc<<' ';
}
return 0;
}
``````
• @ 2019-06-26 22:18:07
``````//不是很难的题目
//主要是考察了模运算和结构体排序的应用
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
int num,w,apple;
}q[100010];
int b[100010];
int cmp(const node&x,const node&y)
{
return x.w>y.w;
}
int cmp2(const node&x,const node&y)
{
return x.num<y.num;
}
int main()
{
int n,m,i;
cin>>n>>m;
for(i=0;i<n;i++)
cin>>b[i];
for(i=0;i<m;i++)
{
cin>>q[i].w;
q[i].num=i;
q[i].apple=0;
}
sort(b,b+n);
sort(q,q+m,cmp);
for(i=0;i<n;i++)
q[i%m].apple+=b[n-i-1];
sort(q,q+m,cmp2);
for(i=0;i<m;i++)
cout<<q[i].apple<<" ";
return 0;
}
``````
• @ 2018-06-09 15:12:12
``````#include <cstdio>
#include <iostream>//包含std::greater
#include <algorithm>
int n,m,a[100001];
struct tt{
int id,w,ans;
}b[100001];
bool cmp1(const tt& a,const tt& b){return a.w>b.w;}//按体重从大到小排序
bool cmp2(const tt& a,const tt& b){return a.id<b.id;}//按初始编号从小到大排序
int main(){
freopen("apple.in","r",stdin),freopen("apple.out","w",stdout);
scanf("%d %d",&n,&m);
for(register int i=0;i<n;++i) scanf("%d",&a[i]);
for(register int i=0;i<m;++i) scanf("%d",&b[i].w),b[i].id=i;
std::sort(&a[0],&a[n],std::greater<int>());//按大小从大到小排序
std::sort(&b[0],&b[m],cmp1);
for(register int i=0;i<n;++i) b[i%m].ans+=a[i];
std::sort(&b[0],&b[m],cmp2);
for(register int i=0;i<m;++i) printf("%d%c",b[i].ans,(i==m-1)?'\n':' ');
}

``````
• @ 2019-07-23 20:10:28

#include <iostream>
using namespace std;
int main()
{
int m,n,b[100000],h[100000],a[100000][2],i,j,k;
cin>>n>>m;
for(i=0;i<100000;i++) {b[i]=0;h[i]=0;a[i][0]=0;a[i][1]=0;}
for(i=0;i<n;i++) cin>>b[i];for(i=0;i<m;i++) {cin>>h[i];a[i][0]=h[i];}
for(i=0;i<n-1;i++) for(j=i+1;j<n;j++) if(b[i]<b[j]) {k=b[i];b[i]=b[j];b[j]=k;}
for(i=0;i<m-1;i++) for(j=i+1;j<m;j++) if(a[i][0]<a[j][0]) {k=a[i][0];a[i][0]=a[j][0];a[j][0]=k;}
j=0;k=0;
for(i=0;i<n;i++)
{
a[k][1]+=b[i];
k++;
if(k==m) k=0;
}
for(i=0;i<m;i++) for(j=0;j<m;j++) if(h[i]==a[j][0]) {cout<<a[j][1]<<' ';break;}
}

• @ 2018-03-22 13:48:03

#include<iostream>
#include<algorithm>
using namespace std;
int a[100000],b[100000],c[100000],d[100000],f[100000],e[100000];
int main()
{
int n,m,g,y,k;
cin>>n>>m;
for (int i=0;i<n;i++)
{
cin>>a[i];
}
for (int i=0;i<m;i++)
{
cin>>b[i];
f[i]=b[i];
}
sort (a,a+n);
sort (b,b+m);
for (int i=0;i<n;i++)
{
c[i]=a[n-1-i];
}
for (int i=0;i<m;i++)
{

g=i;
for (int j=0;j<n;j++)
{
y=j;
for (int l=0;l<(n/m)+1;l++)
{
if (g==y-l*m)
{
e[g]+=c[y];
c[y]=0;
break;
}
}
}
}
for (int i=0;i<m;i++)
{
for (int j=0;j<m;j++)
{
if (b[j]==f[i])
{
cout<<e[m-j-1]<<" ";

break;
}
}
}
return 0;
}

• @ 2018-02-19 16:26:11

for i:=1 to m-1 do write(d[i],' '); writeln(d[m]);
*****虐我无数遍的空格*****

• @ 2017-10-07 18:20:50

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<set>
#define maxa 100000+100
#define FOR(i,x,y) for(i=x;i<=y;++i)
using namespace std;
int a[maxa];
struct node{
int v,num,w;
}e[maxa];
bool comp(node p,node q)
{
return p.v>q.v;
}
bool comp1(node p,node q)
{
return p.num<q.num;
}
bool com1(int p,int q)
{
return p>q;
}
int main()
{
int n,m,i;
cin>>n>>m;
FOR(i,1,n)
cin>>a[i];
sort(a+1,a+n+1,com1);
FOR(i,1,m)
{
cin>>e[i].v;
e[i].num = i;
e[i].w = 0;
}
sort(e+1,e+1+m,comp);
FOR(i,1,n)
{
if(i%m)
e[i%m].w+=a[i];
else
e[m].w+=a[i];
}
sort(e+1,e+1+m,comp1);
FOR(i,1,m)
{
cout<<e[i].w<<" ";
}
return 0;
}

• @ 2017-08-24 20:46:16

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
struct dd
{
int data;//存储陶陶原始序号
int weight;//存储陶陶体重
int total;//存储拿到的苹果
};dd w[100001];
int main()
{
int n,m;
int j=0;
int d[100001];
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>d[i];
for (int i=1;i<=m;i++)
cin>>w[i].weight,w[i].data=i;
sort(d+1,d+n+1);//快速排序苹果重量（从小到大）

for (int i=1;i<m;i++)
for (int j=1;j<=m-i;j++)
if (w[j].weight<w[j+1].weight)
swap(w[j],w[j+1]);//冒泡排序陶陶体重（从大到小）
while (n!=0)//判断苹果数量超过上限
{
if (j==m)//循环陶陶拿取苹果
j=0;
j+=1;
w[j].total+=d[n];//累加每个陶陶获得苹果重量
n=n-1;//从大到小拿取苹果
}
for (int i=1;i<m;i++)
for (int j=1;j<=m-i;j++)
if (w[j].data>w[j+1].data)
swap(w[j],w[j+1]);//根据陶陶的原始序号重新排列顺序
for (int i=1;i<=m;i++)
cout<<w[i].total<<" ";
}

• @ 2017-07-12 20:46:21

1.AC
2.#include<iostream>
#include<algorithm>
#include<cstdio>
#include<iomanip>
using namespace std;
int a[100000],b[100000],c[100000],d[100000],t[100000],e[1000000];
int my_comp(const int & a,const int & b)
{
return a>b;
}
int main()
{
int e[100000]={0};
int t[100000]={0};
int c[100000]={0};
int d[100000]={0};
long long int n,m;
cin>>n>>m;
for(int i=1;i<=n;++i)
{
cin>>a[i];
}
for(int j=1;j<=m;++j)
{
cin>>b[j];
e[j]=b[j];
}
sort(e+1,e+m+1,my_comp);
sort(a+1,a+n+1,my_comp);
int k=0;
for(int j=1;j<=n;++j)
{
++k;
c[k]=a[j]+c[k];
if(k==m)
k=0;
}
int s=1;
while(s<m+1)
{
for(int i=1;i<=m;++i)
{
if(b[i]>e[s+1])
{
d[b[i]]=c[s];
++s;
t[i]=b[i];
b[i]=0;
}
}
}
for(int i=1;i<=m;++i)
cout<<d[t[i]]<<" ";
}

• @ 2016-12-25 16:49:35

编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 2124 KiB, score = 1

测试数据 #1: Accepted, time = 0 ms, mem = 2124 KiB, score = 1

测试数据 #2: Accepted, time = 0 ms, mem = 2124 KiB, score = 1

测试数据 #3: Accepted, time = 0 ms, mem = 2124 KiB, score = 1

测试数据 #4: Accepted, time = 0 ms, mem = 2128 KiB, score = 1

测试数据 #5: Accepted, time = 0 ms, mem = 2128 KiB, score = 1

测试数据 #6: Accepted, time = 15 ms, mem = 2124 KiB, score = 1

测试数据 #7: Accepted, time = 46 ms, mem = 2124 KiB, score = 1

测试数据 #8: Accepted, time = 78 ms, mem = 2128 KiB, score = 1

测试数据 #9: Accepted, time = 93 ms, mem = 2124 KiB, score = 1

Accepted, time = 232 ms, mem = 2128 KiB, score = 10
```C++
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <set>
#include <stack>
#include <queue>
using namespace std;
struct T
{
int weight,num,ans;
};
int ap[100005];
T tt[100005];
bool cmp1(T t1,T t2) //按体重排大~小
{
return t1.weight>t2.weight;
}
bool cmp2(T t1,T t2) //按序号排小~大
{
return t1.num<t2.num;
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>ap[i];
for(int i=1;i<=m;i++)
{

tt[i].num=i;
cin>>tt[i].weight;
}
sort(&ap[1],&ap[n+1],greater<int>());
sort(&tt[1],&tt[m+1],cmp1); //按体重排
for(int i=1;i<=n;i++) //枚举苹果
{
if(i%m)
tt[i%m].ans+=ap[i];
else
tt[m].ans+=ap[i];
}
sort(&tt[1],&tt[m+1],cmp2);

for(int i=1;i<=m;i++)
cout<<tt[i].ans<<' ';
return 0;
}

``````
需要想到枚举苹果  我该开始枚举陶陶各种数组越界
``````
• @ 2016-11-13 12:22:17
``````评测结果
编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 2124 KiB, score = 1
测试数据 #1: Accepted, time = 0 ms, mem = 2120 KiB, score = 1
测试数据 #2: Accepted, time = 0 ms, mem = 2124 KiB, score = 1
测试数据 #3: Accepted, time = 0 ms, mem = 2124 KiB, score = 1
测试数据 #4: Accepted, time = 0 ms, mem = 2120 KiB, score = 1
测试数据 #5: Accepted, time = 0 ms, mem = 2124 KiB, score = 1
测试数据 #6: Accepted, time = 0 ms, mem = 2124 KiB, score = 1
测试数据 #7: Accepted, time = 31 ms, mem = 2124 KiB, score = 1
测试数据 #8: Accepted, time = 46 ms, mem = 2124 KiB, score = 1
测试数据 #9: Accepted, time = 62 ms, mem = 2120 KiB, score = 1
Accepted, time = 154 ms, mem = 2124 KiB, score = 10
代码
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
int h[100001],n,m;
struct T {
int num,weight,ans;
bool operator < (T x) const { return x.num < num; }
}p[100001];
inline bool cmp(T x,T y) { return x.weight > y.weight; }
int main() {
scanf("%d%d",&n,&m);
for (int i = 1;i <= n;i++) scanf("%d",&h[i]);
for (int i = 1;i <= m;i++) {
scanf("%d",&p[i].weight);
p[i].num = i;
}
sort(h+1,h+n+1,greater<int>());
sort(p+1,p+n+1,cmp);
for (int i = 1;i <= n;i++) p[i%m ? i%m : m].ans += h[i];
sort(p+1,p+n+1);
for (int i = m;i >= 1;i--) printf("%d ",p[i].ans);
return 0;
}
``````
• @ 2016-11-12 22:01:31
``````#include<iostream>
#include<algorithm>
using namespace std;
int apple[100010]={0},n,m;
struct q
{
int apple,body,num;
}pupil[100010];
bool cmp(int a,int b)
{
return a>b;
}
int cmp1(q a,q b)
{
if(a.body>b.body)
return 1;
else
return 0;
}
bool cmp2(q a,q b)
{
if(a.num<b.num)
return 1;
else
return 0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>apple[i];
for(int i=1;i<=m;i++)
{
cin>>pupil[i].body;
pupil[i].num=i;
}
sort(&apple[1],&apple[n+1],cmp);
sort(pupil+1,pupil+m+1,cmp1);
for(int i=1;i<=n;i++)
if(i%m)
pupil[i%m].apple+=apple[i];
else
pupil[m].apple+=apple[i];
sort(pupil+1,pupil+m+1,cmp2);
for(int i=1;i<=m;i++)
cout<<pupil[i].apple<<' ';
return 0;
}
``````
• @ 2016-11-12 22:01:04
``````#include<iostream>
#include<algorithm>
using namespace std;
int apple[100010]={0},n,m;
struct q
{
int apple,body,num;
}pupil[100010];
bool cmp(int a,int b)
{
return a>b;
}
int cmp1(q a,q b)
{
if(a.body>b.body)
return 1;
else
return 0;
}
bool cmp2(q a,q b)
{
if(a.num<b.num)
return 1;
else
return 0;
}
int main()
{
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>apple[i];
for(int i=1;i<=m;i++)
{
cin>>pupil[i].body;
pupil[i].num=i;
}
sort(&apple[1],&apple[n+1],cmp);
sort(pupil+1,pupil+m+1,cmp1);
for(int i=1;i<=n;i++)
if(i%m)
pupil[i%m].apple+=apple[i];
else
pupil[m].apple+=apple[i];
sort(pupil+1,pupil+m+1,cmp2);
for(int i=1;i<=m;i++)
cout<<pupil[i].apple<<' ';
return 0;
}
``````
• @ 2016-08-19 09:03:10

{
将people排序(记录它原本的位置)
将apple排序
while 循环 () 一直到 n=0;
}

type
re=record
w,g:longint;
sum:int64;
end;

var
n,m,i,j:longint;
app:array[0..100010]of longint;
ans:array[0..100010]of int64;
peo:array[0..100010]of re;

procedure sort_peo(l,r:longint);
var
i,j,x:longint;
y:re;
begin
i:=l; j:=r;
x:=peo[(l+r) div 2].w;
repeat
while peo[i].w>x do inc(i);
while x>peo[j].w do dec(j);
if not(i>j) then
begin
y:=peo[i]; peo[i]:=peo[j]; peo[j]:=y;
inc(i); j:=j-1;
end;
until i>j;
if l<j then sort_peo(l,j);
if i<r then sort_peo(i,r);
end;

procedure sort_app(l,r:longint);
var
i,j,x,y:longint;
begin
i:=l; j:=r;
x:=app[(l+r) div 2];
repeat
while app[i]>x do inc(i);
while x>app[j] do dec(j);
if not(i>j) then
begin
y:=app[i]; app[i]:=app[j]; app[j]:=y;
inc(i); j:=j-1;
end;
until i>j;
if l<j then sort_app(l,j);
if i<r then sort_app(i,r);
end;

procedure init;
var
i:longint;
begin
for i:=1 to n do read(app[i]);
for i:=1 to m do
begin
peo[i].g:=i;
end;
sort_peo(1,m);
sort_app(1,n);
end;

procedure print;
var
i:longint;
begin
for i:=1 to m do ans[peo[i].g]:=peo[i].sum;
for i:=1 to m do write(ans[i],' ');
end;

begin
init;
while j<>n do
begin
inc(i); inc(j);
if i>m then i:=i-m;
peo[i].sum:=peo[i].sum+app[j];
end;
print;
end.

• @ 2016-07-04 09:58:02

一遍水过。。。。昨晚的阴霾瞬间没了。。。
~~~

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,A[100005];
struct T{
int lable;
int weight;
int ans;
T(){weight=ans=0;}
}B[100005];
int cmp1(int a,int b){
return a>b;
}
int cmp2(T a,T b){
return a.weight > b.weight;
}
int cmp3(T a,T b){
return a.lable < b.lable;
}
int main(){
//freopen("input.txt","r",stdin);
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++) scanf("%d",A+i);
for(int i=0;i<m;i++){ scanf("%d",&B[i].weight);B[i].lable=i;}
sort(A,A+n,cmp1);
sort(B,B+m,cmp2);
for(int i=0;i<n;i++)
B[i%m].ans+=A[i];
sort(B,B+m,cmp3);
for(int i=0;i<m;i++) printf("%d ",B[i].ans);
printf("\n");
return 0;
}

• @ 2016-02-02 21:54:54

AC100留念
只需排序后模拟即可，可是一时想不起来把时间换空间，排了三遍……
具体步骤：
1. 将陶陶们按体重排序
2. 将苹果们按重量排序
3. 模拟摘苹果
4. 将陶陶们按读入序号排回去
5. 输出

不说了，上代码吧……
###Pascal Code
program p1445;
type
Taotao=record
sum,weight,ind:longint;
end;
var
tt:array[1..100005] of Taotao;
apple:array[1..100005] of longint;
i,j,n,m:longint;

procedure qsort(l,r:longint;f:Boolean);//Sort with weight if f=True, else sort with ind
var
i,j,m:longint;
t:Taotao;
begin
i:=l; j:=r;
if f
then m:=tt[(l+r) div 2].weight
else m:=tt[(l+r) div 2].ind;
repeat
if f
then
begin
while tt[i].weight>m do inc(i);
while tt[j].weight<m do dec(j);
end
else
begin
while tt[i].ind<m do inc(i);
while tt[j].ind>m do dec(j);
end;
if i<=j then
begin
t:=tt[i];
tt[i]:=tt[j];
tt[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsort(i,r,f);
if l<j then qsort(l,j,f);
end;

procedure qsortapple(l,r:longint);
var
i,j,m,t:longint;
begin
i:=l; j:=r; m:=apple[(l+r) div 2];
repeat
while apple[i]>m do inc(i);
while apple[j]<m do dec(j);
if i<=j then
begin
t:=apple[i];
apple[i]:=apple[j];
apple[j]:=t;
inc(i);
dec(j);
end;
until i>j;
if i<r then qsortapple(i,r);
if l<j then qsortapple(l,j);
end;

begin //main
{assign(input,'input.in');
reset(input);}
for i:=1 to n do read(apple[i]);
for i:=1 to m do
begin
tt[i].ind:=i;
tt[i].sum:=0;
end;
qsort(1,m,True);
qsortapple(1,n);
j:=1;
for i:=1 to n do
begin
if j>m then j:=1;
inc(tt[j].sum,apple[i]);
inc(j);
end;
qsort(1,m,False);
for i:=1 to m-1 do write(tt[i].sum,' ');
writeln(tt[m].sum);
end.

• @ 2016-01-10 14:21:15

#include<iostream>
#include<algorithm>
#include<cstring>
struct DATA
{
int a,b;
}y[100001];
int cmp1(int c,int d)
{
if (c>d)return 1;
else return 0;
}
int cmp2(const DATA& c,const DATA& d)
{
if (c.a>d.a)return 1;
else return 0;
}
int x[100001],z[100001];
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
for (int i=1;i<=n;i++)
cin>>x[i];
for (int i=1;i<=m;i++)
{
cin>>y[i].a;
y[i].b=i;
}
sort(x+1,x+n+1,cmp1);
sort(y+1,y+m+1,cmp2);
int j=0;
memset(z,0,sizeof(z));
for (int i=1;i<=n;i++)
{
j++;
if (j==m+1)j=1;
z[y[j].b]+=x[i];
}

for (int i=1;i<=m;i++)
{
cout<<z[i]<<" ";
}
}

• @ 2015-10-24 23:02:10

P1445陶陶抢苹果
Accepted

记录信息

评测状态 Accepted
题目 P1445 陶陶抢苹果
递交时间 2015-10-24 23:01:44
代码语言 C++
评测机 VijosEx
消耗时间 153 ms
消耗内存 2104 KiB
评测时间 2015-10-24 23:01:47

评测结果

编译成功

测试数据 #0: Accepted, time = 0 ms, mem = 2100 KiB, score = 1

测试数据 #1: Accepted, time = 0 ms, mem = 2100 KiB, score = 1

测试数据 #2: Accepted, time = 0 ms, mem = 2096 KiB, score = 1

测试数据 #3: Accepted, time = 0 ms, mem = 2100 KiB, score = 1

测试数据 #4: Accepted, time = 0 ms, mem = 2096 KiB, score = 1

测试数据 #5: Accepted, time = 15 ms, mem = 2096 KiB, score = 1

测试数据 #6: Accepted, time = 15 ms, mem = 2096 KiB, score = 1

测试数据 #7: Accepted, time = 31 ms, mem = 2100 KiB, score = 1

测试数据 #8: Accepted, time = 41 ms, mem = 2104 KiB, score = 1

测试数据 #9: Accepted, time = 51 ms, mem = 2100 KiB, score = 1

Accepted, time = 153 ms, mem = 2104 KiB, score = 10

代码

#include <iostream>
#include <stdio.h>
#include <algorithm>

using namespace std;

int n , m , t;
int a[100000 + 2];

struct query
{
int pos , x , ans;
}b[100000 + 2];

inline bool cmp( int a , int b )
{
return a > b;
}

inline bool cmp1( query a , query b )
{
return a.x > b.x;
}

inline bool cmp2( query a , query b )
{
return a.pos < b.pos;
}

int main()
{
scanf( "%d %d" , &n , &m );
for( register int i = 1 ; i <= n ; i++ ) scanf( "%d" , &a[i] );
sort( a + 1 , a + n + 1 , cmp );
for( register int i = 1 ; i <= m ; i++ ) scanf( "%d" , &b[i].x ) , b[i].pos = i;
sort( b + 1 , b + m + 1 , cmp1 );
while( 1 )
{
for( register int i = 1 ; i <= m && i + t <= n ; i++ )
b[i].ans += a[i + t];
t += m;
if( t >= n ) break;
}
sort( b + 1 , b + m + 1 , cmp2 );
for( register int i = 1 ; i <= m ; i++ )
printf( "%d " , b[i].ans );
return 0;
}

ID
1445

5

2845

880

31%

6