-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2244D_Yaroslav_and_Productivity.cpp
More file actions
63 lines (63 loc) · 1.13 KB
/
Copy path2244D_Yaroslav_and_Productivity.cpp
File metadata and controls
63 lines (63 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// Winners never Quit!
#include <bits/stdc++.h> // Problem -
using namespace std;
#define ll long long
#define pr pair<ll, ll>
#define pb push_back
#define fr(i, a, n) for (ll i = a; i < n; i++)
#define frr(i, a, n) for (ll i = n - 1; i >= a; i--)
#define elif else if
bool isprime(ll n)
{
if (n < 2) return false;
for (ll i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
ll pow(ll a, ll b) // O(log(b))
{
ll res = 1;
while (b)
{
if (b & 1) res *= a;
a *= a;
b >>= 1;
}
return res;
}
void solve()
{
ll n,m;
cin>>n>>m;
ll cntmin=0,cntmax=0;
vector<ll> a(n),b(m);
fr(i,0,n) cin>>a[i];
fr(i,0,m) cin>>b[i];
ranges::sort(b);
ll x=0;
fr(i,0,n){
cntmin+=a[i];
cntmax+=a[i];
if(x<m && ((b[x]-1)==i)){
ll y=max(abs(cntmin),abs(cntmax));
cntmax=y;
cntmin=(-1)*y;
x++;
}
}
cout<<cntmax<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
ll T; cin >> T;
while (T--)
solve();
return 0;
}