-1

What is the problem with my code ?

prog.cpp: In function ‘void helper()’: prog.cpp:15:25: error: expected primary-expression before ‘long’ ans = ans + max(long long(0),vec[i]-i);

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

void helper(){
    ll n;
    cin>>n;
    vector<ll>vec(n);
    for(ll i=0;i<n;i++)
        cin>>vec[i];
    sort(vec.begin(),vec.end(),greater<ll>());
    ll ans=0;
    for(ll i=0;i<n;i++){
        ans = ans + max(long long(0),vec[i]-i);
        ans=ans % mod;
    }
    cout<<ans<<endl;
}

int main() {
    int test;cin>>test;
    while(test--){
        helper();
    }
    
    return 0;
}
Evg
  • 25,259
  • 5
  • 41
  • 83
  • 1
    Use `max((long long)0, ven[i]-i);`, or `max( 0ll, vec[i]-i );` – Tim Roberts Feb 04 '22 at 07:40
  • *Please* inform whatever fiend is telling you and your classmates to use `#include ` that they're doing you no favors and [it's a terrible habit](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – WhozCraig Feb 04 '22 at 08:21

2 Answers2

2

You can correct the error following one of these ways: (ll)0 or (long long)0 or 0ll

Md. Faisal Habib
  • 1,014
  • 1
  • 6
  • 14
0

The formal rule is that a constructor like type cast like long long(0) can only have a one word type name, and long long is two words. Oops, just doesn't work.

Using a proper C++ type cast like static_cast<long long>(0) does work. However, for a constant you could just use 0LL and avoid the cast altogether.

BoP
  • 2,310
  • 1
  • 15
  • 24