172722025-06-08 12:41:08algoproGamecpp17Accepted 100/1001.384s1144 KiB
// UUID: 842126da-175f-4e3f-8362-2343eb055e93

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
int n;
pair<int,int> a[111111];
bool f[111111];
void upd(long long int&res,int b,int x){
	if(b%2)res += x;else
		res -= x;
}
int main(){
	int q;
	scanf("%d%d",&n,&q);
	for(int i=1; i<=n; i++){
		scanf("%d",&a[i].first);
		a[i].second = i;
	}
	sort(a+1,a+n+1);
	reverse(a+1,a+n+1);
	while(q--){
		int x;
		scanf("%d",&x);
		int pnt = x;
		long long int res = 0;
		memset(f,0,sizeof(f));
		for(int i=1; i<=n; i++){
			int pos = a[i].second, val = a[i].first;
			while(pnt <= n && f[pnt])pnt++;
			if(pnt > n){
				upd(res, i, val);
			}else
			if(pos > pnt){
				upd(res, pos - x + 1, val);
				f[pos] = true;
			}else{
				upd(res, pnt - x + 1, val);
				f[pnt] = true;
			}
		}
		cout << res << endl;
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask110/10
1Accepted1ms504 KiB
2Accepted1ms316 KiB
subtask220/20
1Accepted2ms520 KiB
2Accepted2ms316 KiB
3Accepted4ms316 KiB
4Accepted8ms316 KiB
subtask370/70
1Accepted25ms316 KiB
2Accepted25ms316 KiB
3Accepted68ms584 KiB
4Accepted79ms564 KiB
5Accepted277ms820 KiB
6Accepted523ms820 KiB
7Accepted368ms912 KiB
8Accepted623ms1088 KiB
9Accepted510ms1076 KiB
10Accepted695ms1076 KiB
11Accepted875ms1076 KiB
12Accepted1.197s1144 KiB
13Accepted774ms1076 KiB
14Accepted1.384s1076 KiB