-1

I wrote the code below to perform few tasks.

Here is my code:

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

int main() {
    int t; cin >> t;
    while (t--) {
        long long int N; cin >> N;
        vector<long long int> cars(N);
        for (long long int i = 0; i < N; ++i) {
            cin >> cars[i];
        }
        sort(cars.begin(), cars.end(), greater<long long int>());

        long long int profit = 0;
        for (long long int i = 0; i < N; ++i) {
            if (cars[i]) {
                profit += cars[i] - i;
            }
        }

        cout << profit << endl;
    }
    return 0;
}

I really don't know why I am facing this error while I am submitting the code. Could anyone please help me in getting out of this. Input The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N. The second line contains N space-separated integers P1,P2,…,PN. Output For each test case, print a single line containing one integer ― the maximum profit Chef can make, modulo 1,000,000,007.

Constraints
1≤T≤25
1≤N≤105
0≤Pi≤109 for each valid i

The inputs are 
2 next line
3 next line
6 6 6 next line
3 next line
0 1 0 

Expected Output
15 next line
1
cs95
  • 274,032
  • 76
  • 480
  • 537

1 Answers1

0

i tried the inputs from your code, and it seems working fine, you just miss the headers needed here. vector, iostream and algorithm, Maybe There's nothing wrong with your code, you're simply running on a platform likely with small memory limits. you need to focus on optimization, but if you have something wrong with the results you need please to provide the idea behind the code, example of input, expected output, current output and ranges of t and N.

check : https://stackoverflow.com/help/minimal-reproducible-example

walid barakat
  • 342
  • 1
  • 3
  • 12
  • i tried the inputs and it seems works fine, but you miss the header in your code – walid barakat Apr 09 '20 at 13:15
  • 2
    @KanigantiSaiTarun No, it's bad practice, don't use that header: https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h – churill Apr 09 '20 at 13:18