Skip to content

Commit

Permalink
meetings
Browse files Browse the repository at this point in the history
  • Loading branch information
megargayu committed Oct 7, 2022
1 parent 3ca010a commit bae00cd
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 15 deletions.
74 changes: 59 additions & 15 deletions contests/silver/2019/december/meetings/meetings.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
#include <bits/stdc++.h>
using namespace std;

#define MAX_N 50000
#define MAX_N 5e4
#define pii pair<int, int>

struct Cow
{
int w, x;
bool operator<(const Cow& o) { return x < o.x; }
int w, x, d;
};

vector<Cow> leftC, rightC;
vector<Cow> cows(MAX_N);
vector<Cow> leftC(MAX_N), rightC(MAX_N);
vector<pii> poi(MAX_N * 50);

int main()
{
ifstream fin("meetings.in");
Expand All @@ -18,20 +21,61 @@ int main()
int N, L;
fin >> N >> L;

int w, x, d;
for (int i = 0; i < N; ++i)
int numLeft = 0, totalW = 0;
for (int i = 0; i < N; ++i)
{
cin >> w >> x >> d;
if (d == -1) leftC.push_back({ w, x });
else rightC.push_back({ w, x });
fin >> cows[i].w >> cows[i].x >> cows[i].d;
numLeft += cows[i].d == -1;
totalW += cows[i].w;
}

sort(leftC.begin(), leftC.end());
sort(rightC.begin(), rightC.end());
sort(cows.begin(), cows.begin() + N, [](const Cow &a, const Cow &b)
{ return a.x < b.x; });

// find T
int i, j, T;

int leftI = 0, rightI = 0;
for (int i = 0; i < N; ++i)
{
if (cows[i].d == -1) leftC[leftI++] = cows[i];
else rightC[rightI++] = cows[i];
}

int poiI = 0;
for (int i = 0; i < leftI; ++i)
poi[poiI++] = {leftC[i].x, cows[i].w};

for (int i = 0; i < rightI; ++i)
poi[poiI++] = {L - rightC[i].x, cows[leftI + i].w};

sort(poi.begin(), poi.begin() + poiI, [](const pii &a, const pii &b)
{ return a.first < b.first; });

int T = -1, w = 0;
for (int i = 0; i < poiI; ++i)
{
w += poi[i].second;
if (w * 2 >= totalW)
{
T = poi[i].first;
break;
}
}

assert(T != -1);

int ans = 0;
int i = 0, j = 0;
for (int l = 0; l < rightI; ++l)
{
while (i < leftI && leftC[i].x < rightC[l].x)
++i;

while (j < leftI && leftC[j].x <= rightC[l].x + T * 2)
++j;

ans += j - i;
}

fout << ans << '\n';

return 0;
}
}
4 changes: 4 additions & 0 deletions contests/silver/2019/december/meetings/meetings.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
3 5
1 1 1
2 2 -1
3 3 -1
1 change: 1 addition & 0 deletions contests/silver/2019/december/meetings/meetings.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2

0 comments on commit bae00cd

Please sign in to comment.