1814C - Search in Parallel - CodeForces Solution


greedy math sortings

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int  mod = 1000000007; 

/*=================================Debug==================================*/
template <typename A, typename B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << '(' << p.first << ", " << p.second << ')'; }
template <typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream& os, const T_container& v) { os << '{'; string sep; for (const T& x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << " " << H; dbg_out(T...); }
 
#define MY
#ifdef MY
#define debug(args...) cerr << "(" << #args << "):", dbg_out(args)
#else
#define debug(args...)
#endif
bool cmp(pair<int , int > x, pair<int , int >y){
    return x.second>y.second; 
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int t;
    cin>>t; 
    while(t--){
        int  n, s1, s2; 
        cin>>n>>s1>>s2; 
        vector<pair<int , int > >a; 
        for(int i=1; i<=n;i++){
            int x; 
            cin>>x; 
            a.push_back(make_pair(i, x)); 
        }
        sort(a.begin(), a.end(), cmp);
        vector<int > x, y; 
        for(auto  i : a){
            int sz1= x.size()+1;
            int sz2 = y.size()+1;
            if(sz1*s1<sz2*s2)x.push_back(i.first); 
            else y.push_back(i.first);
        }
        cout<<x.size()<<" ";
        for(int i : x)cout<<i<<" ";
        cout<<endl;
        cout<<y.size()<<" ";
        for(int  i : y)cout<<i<<" ";
        cout<<endl;
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

1496A - Split it
1666L - Labyrinth
1294B - Collecting Packages
1642B - Power Walking
1424M - Ancient Language
600C - Make Palindrome
1669D - Colorful Stamp
1669B - Triple
1669A - Division
1669H - Maximal AND
1669E - 2-Letter Strings
483A - Counterexample
3C - Tic-tac-toe
1669F - Eating Candies
1323B - Count Subrectangles
991C - Candies
1463A - Dungeon
1671D - Insert a Progression
1671A - String Building
1671B - Consecutive Points Segment
1671C - Dolce Vita
1669G - Fall Down
4D - Mysterious Present
1316B - String Modification
1204A - BowWow and the Timetable
508B - Anton and currency you all know
1672A - Log Chopping
300A - Array
48D - Permutations
677C - Vanya and Label