为什么会RE呢?
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
const int maxk=5010;
int ans[maxn];
struct node{
int ki;
int ti;
int ai;
bool operator <(const node &n) const
{
return ai<n.ai;
}
}sub[maxn],t[maxk];
int si[maxk];
int main()
{
int k;
cin>>k;
int tot=0;
for (int i=1;i<=k;i++)
{
int pi;
cin>>pi;
for (int j=1;j<=pi;j++)
{
tot++;
sub[tot].ki=i;
cin>>sub[tot].ti;
}
cin>>si[i];
}
int n;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>ans[i];
}
//根据题号转答案
for (int i=1;i<=n;i++)
{
sub[i].ai=ans[sub[i].ti];
}
//求多少个子任务的答案的解是相同
tot=0;
int i=1,ki,ai;
while(i<=n)
{
ai=sub[i].ai;
ki=sub[i].ki;
bool b=true;
while(i<=n&&ki==sub[i].ki)
{
if (ai!=sub[i].ai) b=false;
i++;
}
if (b)
{
tot++;
t[tot].ki=ki;
t[tot].ai=ai;
}
}
//按答案排序,
sort(t+1,t+tot+1);
long long cusdf,ansdf=0,ansda=0;
i=1;
while(i<=tot)
{
cusdf=0;
ai=t[i].ai;
//答案相同的不同子任务得分相加
while(i<=tot&&ai==t[i].ai)
{
cusdf+=si[t[i].ki];
i++;
}
if(ansdf<cusdf)
{
ansdf=cusdf;
ansda=ai;
}
}
cout<<ansdf<<endl;
cout<<ansda<<endl;
return 0;
}
/*
2
5 1 2 3 4 5 40
7 1 2 3 4 5 6 7 60
7
1 2 3 4 5 6 7
*/
{
int pi;
cin>>pi;
for (int j=1;j<=pi;j++)
{
tot++;
sub[tot].ki=i;
cin>>sub[tot].ti;
}
cin>>si[i];
}
int n;
cin>>n;
for (int i=1;i<=n;i++)
{
cin>>ans[i];
}
//根据题号转答案
for (int i=1;i<=n;i++)
{
sub[i].ai=ans[sub[i].ti];
}
//求多少个子任务的答案的解是相同
tot=0;
int i=1,ki,ai;
while(i<=n)
{
ai=sub[i].ai;
ki=sub[i].ki;
bool b=true;
while(i<=n&&ki==sub[i].ki)
{
if (ai!=sub[i].ai) b=false;
i++;
}
if (b)
{
tot++;
t[tot].ki=ki;
t[tot].ai=ai;
}
}
//按答案排序,
sort(t+1,t+tot+1);
long long cusdf,ansdf=0,ansda=0;
i=1;
while(i<=tot)
{
cusdf=0;
ai=t[i].ai;
//答案相同的不同子任务得分相加
while(i<=tot&&ai==t[i].ai)
{
cusdf+=si[t[i].ki];
i++;
}
if(ansdf<cusdf)
{
ansdf=cusdf;
ansda=ai;
}
}
cout<<ansdf<<endl;
cout<<ansda<<endl;
return 0;
} /* 2 5 1 2 3 4 5 40 7 1 2 3 4 5 6 7 60 7 1 2 3 4 5 6 7 */