Language: C++

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N=1e5+5;
int n,m,v,p,cnt;
int a[N];
int index[N]; 
int temp[N];
signed main() 
{
	cin>>n>>m>>v>>p;//m个评委,每个评委给v个题目加分，选前p名 
	for (int i=1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1);
//	for (int i=1;i<=n;i++) cout<<a[i]<<" ";cout<<endl;
	if (v<=p)
	{
		for (int i=1;i<=n;i++) if (a[i]+m>=a[n-p+1]) cnt++;
		cout<<cnt<<endl;
	} else
	{
		for (int i=1;i<=n;i++)
		{
			int j=n-i+1;//正数第j名 
			if (j<=p) 
			{
				cout<<n-i+1<<endl;
				break;
			}
			if (i+p-1>=v && a[i]+m>=a[n-p+1]) //取比自己低的人和最高的人加满 
			{
//				cout<<"CASE2"<<endl;
				cout<<n-i+1<<endl;
				break;
			}
			int tmp=v*m-(i+p-1)*m;//还需要给这么多
			if (index[i-1]==0) index[i]=i+1;else index[i]=index[i-1];
			for (;a[index[i]]<=a[i]+m && index[i]<=n-p;index[i]++)
				temp[i]+=a[i]+m-a[index[i]];
			temp[i]+=temp[i-1];
			if (index[i-1]!=0)
			{
				temp[i]+=(a[i]-a[i-1])*(index[i-1]-i-1);
				temp[i]-=m-(a[i]-a[i-1]);
			}
//			printf("index[%d]=%d temp[%d]=%d\n",i,index[i],i,temp[i]);
			if (temp[i]>=tmp && a[i]+m>=a[n-p+1])
			{
				cout<<n-i+1<<endl;
				break;
			}
		}
	}
	return 0;
}


Compiler output:
a.cc:7:12: error: 'long long int index [100005]' redeclared as different kind of entity
    7 | int index[N];
      |            ^
In file included from /usr/include/string.h:462,
                 from /usr/include/c++/14/cstring:43,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:121,
                 from a.cc:1:
/usr/include/strings.h:50:20: note: previous declaration 'const char* index(const char*, int)'
   50 | extern const char *index (const char *__s, int __c)
      |                    ^~~~~
a.cc: In function 'int main()':
a.cc:36:34: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   36 |                         if (index[i-1]==0) index[i]=i+1;else index[i]=index[i-1];
      |                                  ^
a.cc:36:49: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   36 |                         if (index[i-1]==0) index[i]=i+1;else index[i]=index[i-1];
      |                                                 ^
a.cc:36:67: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   36 |                         if (index[i-1]==0) index[i]=i+1;else index[i]=index[i-1];
      |                                                                   ^
a.cc:36:76: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   36 |                         if (index[i-1]==0) index[i]=i+1;else index[i]=index[i-1];
      |                                                                            ^
a.cc:37:38: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   37 |                         for (;a[index[i]]<=a[i]+m && index[i]<=n-p;index[i]++)
      |                                      ^
a.cc:37:59: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   37 |                         for (;a[index[i]]<=a[i]+m && index[i]<=n-p;index[i]++)
      |                                                           ^
a.cc:37:73: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   37 |                         for (;a[index[i]]<=a[i]+m && index[i]<=n-p;index[i]++)
      |                                                                         ^
a.cc:38:56: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   38 |                                 temp[i]+=a[i]+m-a[index[i]];
      |                                                        ^
a.cc:40:34: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   40 |                         if (index[i-1]!=0)
      |                                  ^
a.cc:42:62: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   42 |                                 temp[i]+=(a[i]-a[i-1])*(index[i-1]-i-1);
      |                                                              ^