1613B - Absent Remainder - CodeForces Solution


greedy implementation sortings *1000

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n=int(input())
    arr=list(map(int,input().split()))
    arr.sort()
    num=arr[0]
    cnt=0
    for i in range(1,n):
        cnt+=1
        ar=[]
        ar.append(arr[i])
        ar.append(num)
        if cnt>n//2:
            break
        print(*ar)

C++ Code:

                        #include <vector>
                        #include <iostream>
                        #include <map>
                        #include <math.h>
                        #include <algorithm>
                        #include <string>
                        #include <iomanip>
                        #include <stack>

                        #define ll long long
                        using namespace std;
                        template<typename _Tp>
                        istream& operator >> (istream& i, vector<_Tp>& v){
                          for(_Tp& x : v)
                            i >> x;
                          return i;
                        }

                        long long roundup(long long a, long long b){
                            if(a%b == 0){
                                return a/b;
                            }
                            else return (a/b)+1;
                        }
                        int oproundup(int a, int b){
                          if(a%b == 0){
                            return (a/b)+1;
                          }
                          else return (a/b)+1;
                        }

                        bool isprime(ll n){ //QUICKEST WAY TO DETERMINE IF A NUMBER IS PRIME OR NOT
                        if(n == 2){
                          return true;
                        }
                        if(n == 1){
                          return false;
                        }
                            for(ll i = 2; i < sqrt(n)+1; i++){
                                if(n%i==0) return false;
                            }
                            return true;
                        }
                        long long gcd(long long int a, long long int b)
                        {
                          if (b == 0)
                            return a;
                          return gcd(b, a % b);
                        }

                        // Function to return LCM of two numbers
                        long long lcm(long long a, long long b)
                        {
                            return (a / gcd(a, b)) * b;
                        }
                        int addallup(double n){

                            return (roundup(n,2)*(2 + (n - 1)));
                        }
                        void output(bool t){
                          if(t == false){
                            cout << "NO";
                          }
                          else cout << "YES";
                        }
                        map<char,int> mp;
                        map<int,map<char,int>> maps;
                        int factorial(int n){
                          int ans = 1;
                          for(int i = 1; i <= n; i++){
                            ans*=i;
                          }
                          return ans;
                        }
                        string to_lower(string s){
                          for(int i = 0; i < s.length(); i++){
                            if(s[i] >= 'a'){
                              s[i] =  (s[i]-32);
                            }
                          }
                          return s;
                        }
                         int getfull(char c, int leng){
                              string s;
                              for(int i = 0; i < leng; i++){
                                   s+=c;
                              }
                              return stoi(s);
                         }
                         string bin(long n)
                      {
                        long i;
                        string s;
                        s+='0';
                        for (i = 1 << 30; i > 0; i = i / 2)
                        {
                          if((n & i) != 0)
                          {
                            s+='1';
                          }
                          else
                          {
                            s+='0';
                          }
                        }
                        return s;
                      }
                      int binaryToDecimal(string n)
                    {
                        string num = n;
                        int dec_value = 0;

                        // Initializing base value to 1, i.e 2^0
                        int base = 1;

                        int len = num.length();
                        for (int i = len - 1; i >= 0; i--) {
                            if (num[i] == '1')
                                dec_value += base;
                            base = base * 2;
                        }

                        return dec_value;
                    }
                    void s(vector<int> v){
                        sort(v.begin(), v.end());
                    }

                    bool issquare(int n){
                      if(floor(sqrt(n)) == sqrt(n)) return true;


                      return false;
                    }
                    #define read(n) cin >> n;
                    long long int fast_exp(int base, int exp)
                    {
                        if(exp==1)
                        return base;
                        else
                        {
                            if(exp%2 == 0)
                            {
                                long long int base1 = pow(fast_exp(base, exp/2),2);
                                if(base1 >= 1000000007)
                                return base1%1000000007;
                                else
                                return base1;
                            }
                            else
                            {
                                long long int ans = (base*  pow(fast_exp(base,(exp-1)/2),2));
                                if(ans >= 1000000007)
                                return ans%1000000007;
                                else
                                return ans;
                            }
                        }
                    }

                    ll xorupton(ll x){
                        ll xxor = 0;
                        if(x%4 == 1){
                                xxor = 1;
                            }
                            else if(x%4 == 2){
                                xxor = x+1;
                            }
                            else if(x%4==3){
                                xxor = 0;
                            }
                            else xxor = x;
                        return xxor;
                    }
                    #define read2(n,m) cin >> n >> m;
                      void solve(int tt){
                            int n;
                            cin >> n;
                            vector<int> v;
                            map<int,bool> mp;
                            for(int i = 0; i < n; i++){
                                int x;
                                cin >> x;
                                v.push_back(x);
                                mp[x]=1;
                            }
                            int buff = 0;
                            sort(v.rbegin(), v.rend());
                            for(int i = 0; i < v.size()/2; i++){
                                cout << v[i] << " " << v[v.size() - 1] << "\n";
                            }
                        }


                      int main(){
                         int t = 1;
                         cin >> t;
                         int x = 1;
                         while(t--){
                              solve(x);
                              x++;
                         }
                      }


Comments

Submit
0 Comments
More Questions

394. Decode String
902. Numbers At Most N Given Digit Set
221. Maximal Square
1200. Minimum Absolute Difference
1619B - Squares and Cubes
1619A - Square String
1629B - GCD Arrays
1629A - Download More RAM
1629C - Meximum Array
1629D - Peculiar Movie Preferences
1629E - Grid Xor
1629F1 - Game on Sum (Easy Version)
2148. Count Elements With Strictly Smaller and Greater Elements
2149. Rearrange Array Elements by Sign
2150. Find All Lonely Numbers in the Array
2151. Maximum Good People Based on Statements
2144. Minimum Cost of Buying Candies With Discount
Non empty subsets
1630A - And Matching
1630B - Range and Partition
1630C - Paint the Middle
1630D - Flipping Range
1328A - Divisibility Problem
339A - Helpful Maths
4A - Watermelon
476A - Dreamoon and Stairs
1409A - Yet Another Two Integers Problem
977A - Wrong Subtraction
263A - Beautiful Matrix
180C - Letter