Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3321f3c

Browse files
Added problems
1 parent 2e5345a commit 3321f3c

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

‎sorting_and_searching/playlist.cpp‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long int li;
6+
typedef long long int lli;
7+
typedef vector<long long int> vlli;
8+
typedef vector<int> vi;
9+
typedef stack<long long int> slli;
10+
11+
void task()
12+
{
13+
14+
lli lenSongs;
15+
cin >> lenSongs;
16+
17+
vector<int> songs(lenSongs);
18+
19+
for (lli i = 0; i < lenSongs; i++)
20+
{
21+
cin >> songs[i];
22+
}
23+
24+
map<lli, lli> location;
25+
26+
lli r = 0;
27+
lli l = 0;
28+
29+
lli currentStreak = 0;
30+
lli maxStreak = 0;
31+
32+
while (r < lenSongs)
33+
{
34+
35+
lli song = songs[r];
36+
37+
if (location.find(songs[r]) == location.end() || location[songs[r]] == 0)
38+
{
39+
currentStreak++;
40+
maxStreak = max(maxStreak, currentStreak);
41+
location[songs[r]]++;
42+
r++;
43+
}
44+
else
45+
{
46+
currentStreak--;
47+
location[songs[l]]--;
48+
l++;
49+
}
50+
}
51+
52+
cout << maxStreak << '\n';
53+
}
54+
55+
int main()
56+
{
57+
58+
ios::sync_with_stdio(0);
59+
cin.tie(0);
60+
61+
task();
62+
63+
return 0;
64+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#include <bits/stdc++.h>
2+
3+
using namespace std;
4+
5+
typedef long int li;
6+
typedef long long int lli;
7+
typedef vector<long long int> vlli;
8+
typedef vector<int> vi;
9+
typedef stack<long long int> slli;
10+
11+
void task() {
12+
13+
lli lenSticks;
14+
15+
cin>>lenSticks;
16+
17+
vector<lli> sticks(lenSticks);
18+
19+
for(lli i = 0; i < lenSticks; i++) {
20+
cin>>sticks[i];
21+
}
22+
23+
sort(sticks.begin(), sticks.end());
24+
25+
lli median = sticks[lenSticks/2];
26+
27+
lli cost = 0;
28+
29+
for(lli i = 0; i < lenSticks; i++) {
30+
cost += abs(sticks[i] - median);
31+
}
32+
33+
cout<<cost<<'\n';
34+
35+
36+
37+
}
38+
39+
int main() {
40+
41+
ios::sync_with_stdio(0);
42+
cin.tie(0);
43+
44+
task();
45+
46+
return 0;
47+
}

‎towers.cpp‎

Whitespace-only changes.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /