Skip to content

Commit

Permalink
stacking
Browse files Browse the repository at this point in the history
  • Loading branch information
megargayu committed Oct 8, 2022
1 parent 477f064 commit b75d990
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
37 changes: 37 additions & 0 deletions contests/bronze/2012/january/stacking/stacking.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// submitted to https://www.spoj.com/problems/HAYBALE/

#include <bits/stdc++.h>
using namespace std;

#define MAX_N 1000000

vector<int> haybales(MAX_N + 5, 0);

int main()
{
//ifstream fin("stacking.in");
//ofstream fout("stacking.out");

int N, K;
cin >> N >> K;

int a, b;
for (int i = 0; i < K; ++i)
{
cin >> a >> b;
--a, --b;
++haybales[a];
--haybales[b + 1];
}

for (int i = 1; i < N; ++i)
{
haybales[i] += haybales[i - 1];
}

sort(haybales.begin(), haybales.begin() + N);

cout << haybales[N / 2] << '\n';

return 0;
}
5 changes: 5 additions & 0 deletions contests/bronze/2012/january/stacking/stacking.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
7 4
5 5
2 4
4 6
3 5
Empty file.

0 comments on commit b75d990

Please sign in to comment.