搞不懂Submission Error是什麼類型的錯誤。。。
[cpp]
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n && n)
{
int sum = 0;
multiset<int> a;
while(n--)
{
int t;
cin>>t;
while(t--)
{
int temp;
cin>>temp;
a.insert(temp);
}
set<int>::iterator it_max = max_element(a.begin(),a.end());
set<int>::iterator it_min = min_element(a.begin(),a.end());
sum += (*it_max) - (*it_min);
a.erase(it_max);
a.erase(it_min);
}
cout<<sum<<endl;
}
}
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int n;
while(cin>>n && n)
{
int sum = 0;
multiset<int> a;
while(n--)
{
int t;
cin>>t;
while(t--)
{
int temp;
cin>>temp;
a.insert(temp);
}
set<int>::iterator it_max = max_element(a.begin(),a.end());
set<int>::iterator it_min = min_element(a.begin(),a.end());
sum += (*it_max) - (*it_min);
a.erase(it_max);
a.erase(it_min);
}
cout<<sum<<endl;
}
}
估計會超時,改成優先隊列會好很多