codeforces round #683 div2 (div2第二场)

第一题就是直接1,2,3,4,5
就行,这样的话,原来少的加的就多了,多的加的是少的
第二题,其实还是有点思维含量的。就是规定了无限次操作,如果有偶数个负数(包含0),那么就可以把所有数全变成正数,无论相邻不相邻。
第三题。
太狗了,又是爆了int,以后tm真是猪了,哎,忘了忘了,很明显就是要开int呀,真垃圾
反正就是排个序,(从小到大),然后从后面装。

#include <bits/stdc++.h>

using namespace std;
#define ll long long
const int maxn = 2e5 + 10;
struct node
{
    
    
    int p;
    ll we;
} w[maxn];

bool cmp(node a,node b )
{
    
    
  if(a.we!=b.we) return a.we<b.we;
  else return a.p<b.p;
}
 vector<int> v;
int main()
{
    
    
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--)
    {
    
    
        ll n, W;
        cin >> n >> W;
        for(int i=1;i<=n;i++)
        {
    
    
            int x;
            cin>>x;
            w[i].p=i;
            w[i].we=x;
        }
        bool flag = false;
        ll x = W * 1.0 / 2 + 0.5;
       
        ll sum = 0;
        sort(w + 1, w + 1 + n, cmp);
        for (int i=n;i>=1;i--)
        {
    
    
            if (sum+w[i].we <= W)
            {
    
    
                sum += w[i].we;
                v.push_back(w[i].p);
            }
        }
        //cout<<sum<<endl;
        if (sum < (W+1)/2)
            cout << "-1" << endl;
        else
        {
    
    
            cout << v.size() << endl;
            for (int i = 0; i < v.size(); i++)
                cout << v[i] << " ";
            cout << endl;
        }
        v.clear();
    }

}

人傻了,人傻了

猜你喜欢

转载自blog.csdn.net/qq_46264636/article/details/109718576