Codeforces and Polygon may be unavailable from December 6, 19:00 (UTC) to December 6, 21:00 (UTC) due to technical maintenance. ×

Why am i getting wrong answer?

Revision en3, by CandidFlakes, 2023-07-26 20:28:47

I was trying to solve this question. After trying enough i finally read the tutorial. Suppose the minimum number, is a[0]=600. Then we need to calculate how many elements of size 2*600-1=1999 can we form i.e. we simply need to divide each of the a[i] by 1999 and add each of them. But this code is giving wrong results.

#include <bits/stdc++.h>
using namespace std;

#define MULTI int _T; cin >> _T; while(_T--)

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    MULTI
    {
      int n;
      cin>>n;
      vector<int> a(n);
      long long sum = 0;
      for(int i=0;i<n;++i)
      {
        cin>>a[i];
      }
      for(int i = 0;i<n;++i)
      {
        sum+=(a[i])/(2*a[0]-1);
      }
      cout<<sum<<endl;
    }
}


I will be thankful for any help!

Tags lower bound, upper_bound

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English CandidFlakes 2023-07-26 20:28:47 112 Added some more detail to make my doubt clearer. (published)
en2 English CandidFlakes 2023-07-26 20:23:51 836 Tiny change: 'this code #include <' -> 'this code \n\n#include <' (saved to drafts)
en1 English CandidFlakes 2023-07-25 13:43:46 463 Initial revision (published)