Problem Link
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
const int N = 1e5;
struct node
{
int trainer;
int day;
int sadness;
node()
{
}
node(int t, int d, int s)
{
trainer = t;
day = d;
sadness = s;
}
};
bool comparator(node a, node b)
{
return a.sadness > b.sadness;
}
int main()
{
long long result;
int test, n, D, d, t, s;
int freq[N + 1], sad[N + 1];
vector<node> v;
node temp;
cin >> test;
while(test--)
{
cin >> n >> D;
memset(freq, 0, sizeof freq);
memset(sad, 0, sizeof sad);
result = 0;
v.clear();
set<int> daySet;
for (int i = 0; i < D; i++) {
daySet.insert(i);
}
for(int i = 0; i < n; i++)
{
cin >> d >> t >> s;
freq[i] = t;
sad[i] = s;
v.push_back(node(i, d - 1, s));
}
sort(v.begin(), v.end(), comparator);
for(int j = 0; j < n; j++)
{
temp = v[j];
while(freq[temp.trainer] > 0)
{
auto iter = daySet.lower_bound(temp.day);
if(iter == daySet.end())
break;
else
{
freq[temp.trainer]--;
daySet.erase(iter);
}
}
}
for(int i = 0; i < n; i++)
{
result += (long long)sad[i] * (long long) freq[i];
}
cout << result << endl;
}
return 0;
}
#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
const int N = 1e5;
struct node
{
int trainer;
int day;
int sadness;
node()
{
}
node(int t, int d, int s)
{
trainer = t;
day = d;
sadness = s;
}
};
bool comparator(node a, node b)
{
return a.sadness > b.sadness;
}
int main()
{
long long result;
int test, n, D, d, t, s;
int freq[N + 1], sad[N + 1];
vector<node> v;
node temp;
cin >> test;
while(test--)
{
cin >> n >> D;
memset(freq, 0, sizeof freq);
memset(sad, 0, sizeof sad);
result = 0;
v.clear();
set<int> daySet;
for (int i = 0; i < D; i++) {
daySet.insert(i);
}
for(int i = 0; i < n; i++)
{
cin >> d >> t >> s;
freq[i] = t;
sad[i] = s;
v.push_back(node(i, d - 1, s));
}
sort(v.begin(), v.end(), comparator);
for(int j = 0; j < n; j++)
{
temp = v[j];
while(freq[temp.trainer] > 0)
{
auto iter = daySet.lower_bound(temp.day);
if(iter == daySet.end())
break;
else
{
freq[temp.trainer]--;
daySet.erase(iter);
}
}
}
for(int i = 0; i < n; i++)
{
result += (long long)sad[i] * (long long) freq[i];
}
cout << result << endl;
}
return 0;
}
Comments
Post a Comment