1471A - Strange Partition - CodeForces Solution


greedy math number theory *900

Please click on ads to support us..

Python Code:

from math import ceil
T = int(input())
 
for case in range(T):
    n, x = map(int, input().split())
    a = list(map(int, input().split()))
    
    min = ceil(sum(a)/x)
    max = 0
    for i in a:
        max += ceil(i/x)
    print(min, max)

C++ Code:

/* author:prasad patil
   codeforces:rocklee07
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
void prasad()
{
    ll n,x; cin>>n>>x;
    vector<ll>v(n);
    for(ll i=0;i<n;i++) cin>>v[i];
    ll mx=0,mn=0;
    for(ll i=0;i<n;i++)
    {
        if((v[i]%x)!=0)
        {
            mx+=((v[i]/x)+1);
        }
        else
        {
            mx+=(v[i]/x);
        }
    }
    ll temp=0;
    for(ll i=0;i<n;i++)
    {
        temp+=(v[i]%x);
        mn+=(v[i]/x);
    }
    mn+=(temp/x);
    if((temp%x)!=0) mn++;
    cout<<mn<<" "<<mx<<endl;
}           

int main()
{
          ios_base::sync_with_stdio(false);
      cin.tie(NULL); cout.tie(NULL);
          ll t; cin>>t;
          while(t--)
          {
            prasad();
          }
          return 0;
}


Comments

Submit
0 Comments
More Questions

1426C - Increase and Copy
520C - DNA Alignment
767A - Snacktower
1365A - Matrix Game
714B - Filya and Homework
31A - Worms Evolution
1691A - Beat The Odds
433B - Kuriyama Mirai's Stones
892A - Greed
32A - Reconnaissance
1236D - Alice and the Doll
1207B - Square Filling
1676D - X-Sum
1679A - AvtoBus
1549A - Gregor and Cryptography
918C - The Monster
4B - Before an Exam
545B - Equidistant String
1244C - The Football Season
1696B - NIT Destroys the Universe
1674A - Number Transformation
1244E - Minimizing Difference
1688A - Cirno's Perfect Bitmasks Classroom
219A - k-String
952A - Quirky Quantifiers
451B - Sort the Array
1505H - L BREAK into program
171E - MYSTERIOUS LANGUAGE
630D - Hexagons
1690D - Black and White Stripe