include[HTML_REMOVED]
include[HTML_REMOVED]
include[HTML_REMOVED]
using namespace std;
int P,D,n;
const int N = 1e5 + 10;
vector[HTML_REMOVED]> a;
int p[N];
int find(int x) // 只是起到了一个向前溯源的操作
{
if(p[x] != x) p[x] = find(p[x]);
return p[x];
}
int main(void)
{
ios :: sync_with_stdio(false);
cin.tie(0);
while(cin >> n)
{
int time_max = 0,res = 0;
for(int i = 0;i < n;i++)
{
cin >> P >> D;
a.push_back({-P,D});
time_max = max(time_max,D);
}
sort(a.begin(),a.end());
for(auto &it : a)
{
it.first *= -1;
}
for(int i = 0 ; i <= time_max ; i++) p[i] = i;
for(int i = 0 ; i < n ; i++)
{
int value = a[i].first;
int time = a[i].second;
int pos = find(time);
if(pos > 0)
{
res += value;
p[pos] -= 1;
cout << "Value = "<<value<<" "<<"time ="<<time;
for(int i = 0;i <= time_max;i++) cout<< " " << p[i] << " ";
cout << endl;
}
}
cout << res << endl;
a.clear();
}
return 0;
}
```