#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define ls id<<1,l,mid #define rs id<<1|1,mid+1,r #define OFF(x) memset(x,-1,sizeof x) #define CLR(x) memset(x,0,sizeof x) #define MEM(x) memset(x,0x3f,sizeof x) #define rep(i,a,b) for (int i=a;i=b;i--) typedef long long ll ; typedef pair pii ; const int maxn = 1e5+50 ; const int inf = 0x3f3f3f3f ; const int MOD = 1e9+7 ; bool cmp(const int &c,const int &d) { return c > d ;} int a[maxn],b[maxn],flag[maxn]; int m,n,t; int main () { #ifdef LOCAL freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin); #endif scanf("%d",&t); while (t--) { CLR(flag); scanf("%d%d",&n,&m); for (int i=0;i q; while (!q.empty()) q.pop(); for (int i=0;im) break; else ans+=a[i],q.push(j),flag[j]=1; } if (!q.empty()) for (int i=m-1;i>q.front();i--) { if (!flag[i]) { q.push(i); q.pop(); } } while (!q.empty()) { ans-=b[q.front()]; q.pop(); }*/ ll ans=0; for (int i=0;i