#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 2e6+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
ll tot[nax], s[nax], e[nax], t[nax], cnv[nax],pref[nax], rev[nax];
set<int> ind;
map<int,int> cnt;
int main()
{
optimise;
int n,x,ka;
cin >> n >> ka >> x;
ll res = 0;
for (int i = 0; i < n; ++i)
{
cin >> s[i] >> t[i] >> e[i];
ind.insert(s[i]+x);
ind.insert(s[i]);
ind.insert(e[i]+x+1);
ind.insert(e[i]+1);
ind.insert(e[i]+x);
ind.insert(e[i]);
ind.insert(s[i]+t[i]+x);
ind.insert(s[i]+t[i]);
}
int k = 0;
for(auto y : ind){
cnv[y] = k;
rev[k] = y;
k++;
}
for (int i = 0; i < n; ++i)
{
cnt[cnv[s[i]] +1]++;
cnt[cnv[e[i] + 1] +1]--;
tot[cnv[s[i] + t[i]] +1]++;
tot[cnv[e[i] + 1] +1]--;
}
for (int i = 1; i < k; ++i)
{
cnt[i] += cnt[i-1];
tot[i] += tot[i-1];
}
for (int i = 1; i < k; ++i)
{
pref[i] = pref[i-1];
if(cnt[i-1] >= ka) pref[i] += (rev[i-1]-rev[i-2])*tot[i-1];
}
for (int i = 0; i < k; ++i)
{
int to = cnv[rev[i]+x]+1;
res = max(res, pref[to] - pref[i+1]);
}
cout << res << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |