Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:64000000000") using namespace std; const double EPS = 1e-9; const int INF = (int)(2e9 + 0.5); const int MAXN = 201000; struct DoublyLinkedList { int next[MAXN]; int prev[MAXN]; void insert(int x, int pos) { prev[x] = pos; next[x] = next[pos]; pr...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq n = int(input()) line = input() t = line.count('B') if t > n / 2: t = n - t print(t) couple = [] skill = list(map(int,input().split())) for i in range(0,n-1): if line[i] != line[i+1]: t = abs(skill[i]-skill[i+1]) couple.append([t,i,i+1]) heapq.heapify(couple) answer = [] exception =...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; char *student; int *arr; struct node { int x; int y; int val; }; std::vector<node> v; std::vector<node> out; struct edge { int v; edge *left; edge *right; }; edge *ed; bool *flag; bool comp(node &a, node &b) { return (!(a.val < b.val || (a.val == b.val && a.x ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 200000 + 10; struct st { int a, b; st(int A, int B) { a = A; b = B; } }; int n, num[MAXN], tree[MAXN]; char g[MAXN]; bool mark[MAXN]; vector<pair<int, int> > answer; struct cmp { bool operator()(const st &a, const st &b) { return abs(num...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int main() { string str; long long int n, bef[200005], aft[200005], skill[200005]; priority_queue< pair<long long int, pair<long long int, long long int> >, vector<pair<long long int, pair<long long int, long long int> > >, greater<pair<long long int...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct P { int a, b, c; P() {} P(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {} void print() { printf("%d %d\n", a, b); } }; bool operator<(P a, P b) { if (a.c != b.c) return a.c > b.c; return a.a > b.a; } int n; char sex[200010]; int val[200010]; void input()...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.PriorityQueue; import java.util.Scanner; public class C { public static int[] a; public static int n; public static H[] s; public static boolean[]...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct dancerInfo { int delta, num, num2; dancerInfo(int _delta = 0, int _num = 0, int _num2 = 0) { delta = _delta; num = _num; num2 = _num2; } bool operator<(const dancerInfo a) const { return delta < a.delta || delta == a.delt...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e1) { cout << e1 << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2 * 1e5 + 5; int vis[N], ll[N], rr[N], skill[N]; struct node { int u, v, c; }; inline bool operator<(const node a, const node b) { if (a.c ^ b.c) return a.c > b.c; else return a.u > b.u; } priority_queue<node> q; int main() { int n, i, j = 0, s...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; void solve() { long long n; cin >> n; string str; cin >> str; char ch[n + 5]; long long lvl[n + 5]; long long l[n + 5]; long long r[n + 5]; for (long long i = 1; i <= n; i++) ch[i] = str[i - 1]; for (long long i = 1; i <= n; i++) cin >> lvl[i]; for (in...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; set<pair<int, pair<int, int>>> s; set<pair<int, pair<int, int>>>::iterator it; vector<pair<int, int>> ans; int n, v[N], nex[N], last[N]; char a[N]; bool checking[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; scanf("%d%s"...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> inline int Abs(int K) { return K > 0 ? K : -K; } struct ele_t { int pA, pB, val; bool operator<(const ele_t &cmp) const { if (val != cmp.val) return val > cmp.val; else return pA > cmp.pA; } ele_t() {} ele_t(int a, int b, int c) { pA = a, pB = b, val = c; } }; stru...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); struct debugger { template <typename T> debugger& operator,(const T& v) { cerr << v << " "; return *this; } } dbg; char gender[200005]; int prevv[200005], nextt[200005], skill[200005]; priority_queue<pair<int, int> > q; vector<pai...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200000; pair<int, pair<int, int> > ms(int a, int b, int c) { return make_pair(a, make_pair(b, c)); } int x[N]; char s[N + 1]; bool viz[N]; int m = 0; int l[N], r[N]; int r1[N], r2[N]; priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int>...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct ptrs { int lef, rig; ptrs(int _lef = 0, int _rig = 0) { lef = _lef; rig = _rig; } }; ptrs ptr[N]; string s; set<pair<pair<int, int>, int> > dan; int a[N]; bool use[N]; vector<int> ansf, anss; bool ok(int i, int j) { return s[i] =...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; const int INF = 1e9; const long long LINF = 1e18; const int WOW = 40000; const int NIL = 0; const int dy[8] = {1, 0, -1, 0, 1, 1, -1, -1}; const int dx[8] = {0, 1, 0, -1, 1, -1, 1, -1}; const double PI = 2 * acos(0); const int MAXN = 2e5 + 5; int l[...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
# -*- coding: utf-8 -*- """ Created on Sat May 7 10:46:00 2016 @author: Alex """ import heapq, sys n = int(input()) sex = input() r = [i+1 for i in range(n)] l = [i-1 for i in range(n)] skill = list(map(int,input().split())) result = [] answer = [] cnt = 0 for i in range(n-1): if sex[i]!=sex[i+1]: heapq.h...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq as hq n=int(input()) s=input() a=list(map(int,input().split())) pre=[i-1 for i in range(n)] nxt=[i+1 for i in range(n)] free=[1 for i in range(n)] line=[(abs(a[i]-a[i+1]),i,i+1) for i in range(n-1) if s[i]!=s[i+1]] hq.heapify(line) ans=[] while line: t,ppre,pnxt=hq.heappop(line) if free[ppre] and ...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int main() { set<int> mn, all; map<int, set<pair<int, int> > > ma; int n, i, g, x, y; cin >> n; string st; cin >> st; vector<int> a(n), b(n); for (i = 0; i < n; i++) { cin >> a[i]; } vector<pair<int, int> > c; for (i = 0; i < n; i++) { all.inse...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
from heapq import heappush,heappop,heapify n=int(input()) symbols=input() skl=list(map(int,input().split())) LMap=[i-1 for i in range(n+1)] RMap=[i+1 for i in range(n+1)] LMap[1],RMap[n]=1,n h=[] res=[] cnt=0 B=symbols.count("B") N=min(n-B,B) ind=[True]*(n+1) h=[] for i in range(n-1) : if symbols[i]!=symbols[i+1] :...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 1000 * 100 + 10; string str; set<pair<int, pair<int, int> > > s; struct node { int pre, next, key; bool g, val; }; vector<pair<int, int> > ans; node a[MAXN]; int n; int main() { cin >> n >> str; for (int i = 0; i < n; i++) { scanf("%d", &a[i...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int n, m, L, R; int c[200000], l[200000], r[200000]; bool used[200000]; char sex[200000]; set<pair<int, pair<int, int> > > q; vector<pair<int, int> > vp; pair<int, pair<int, int> > v; int main() { scanf("%d\n", &n); for (int i = 0; i < n; i++) { scanf("%c", &sex[i])...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e+5 + 5; int n, a[N]; char ty[N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> ty[i]; for (int i = 1; i <= n; i++) cin >> a[i]; set<pair<int, pair<int, int>>> st; set<int> elt; for...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX; const int MAX = 200005; int a[MAX], l[MAX], r[MAX]; bool boy[MAX]; set<pair<int, int> > dif; int val(int p) { if (l[p] == -1) { if (boy[r[p]] != boy[p]) return r[p]; return -1; } if (r[p] == -1) { if (boy[l[p]] != boy[p]) return l[...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct Mok { int skil; bool lyt; int i; bool pan = false; list<Mok *>::iterator it; }; struct Pora { int del; int i, j; Mok *a, *b; bool operator<(const Pora &o) const { if (del == o.del) return i < o.i; return del < o.del; } Pora(Mok *x, Mok *...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> double const EPS = 3e-8; using namespace std; template <class T> T gcd(T a, T b) { return (b != 0 ? gcd<T>(b, a % b) : a); } template <class T> T lcm(T a, T b) { return (a / gcd<T>(a, b) * b); } template <class T> inline T bigmod(T p, T e, T M) { if (e == 0) return 1; if (e % 2 == 0) { ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const long long M = 1e9 + 7, inf = 1e18; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; int n; string str; cin >> n >> str; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; ; set<pair<int, pair<int, int> > > s; set<...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; vector<int> a; vector<bool> was; priority_queue<pair<int, pair<int, int> > > q; vector<pair<int, int> > ans; vector<int> l, r; int n; int lpred(int i) { int x = i; while (i >= 0 && was[i] == true) i = l[i]; while (x != i) { int c = x; x = l[x]; l[c] = i; ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int N, ans, C[200005], L[200005], R[200005]; bool visit[200005], flag; char P[200005]; struct stuff { int A, B; } tmp; struct cmp { bool operator()(stuff a, stuff b) { if (abs(C[a.A] - C[a.B]) != abs(C[b.A] - C[b.B])) return abs(C[a.A] - C[a.B]) < abs(C[b.A] -...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
from heapq import heappushpop, heapify,heappop,heappush n=int(input()) li = input() a = list(map(int, input().split())) h,seq = [],[] dan = [0]*(n+1) for i in range(n+1)[2:n]: #dan[i]=(Node(li[i-1],i-1,i+1)) dan[i]=[i-1,i+1] #dan[1]=(Node(li[0],None,2)) dan[1] = [None,2] #dan[n]=(Node(li[n-1],n-1,None)) dan[n] ...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import java.awt.Point; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.ArrayList; import java.util.PriorityQueue; public class C { static class Que_Elements i...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
__author__ = 'Utena' from heapq import heappushpop, heapify,heappop,heappush n=int(input()) danced=[0]*(n+1) gender=[0]+list(input()) skill=[0]+list(map(int,input().split())) next=[0]+[i+1 for i in range(1,n)]+[0] prev=[0]+[i for i in range(n)] ans=[] line=[] total=0 for i in range(1,n): x,y=i,i+1 if gender[x]=...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; pair<long long, long long> tree[1000009]; long long ar[1000009], pr[1000009], L[1000009], R[1000009], LEF[1000009], RI[1000009]; vector<pair<long long, long long> > vec; void init(long long node, long long beg, long long end) { if (beg == end) { tree[node] = make_...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int INF = 2147483647; const double PI = 3.141592653589793; const int N = 200005; int n, pl[N], um[N], k1, k2, lewy[N], prawy[N], i; pair<int, pair<int, int> > p; set<pair<int, pair<int, int> > > zbior; vector<pair<int, int> > wek; char t[N]; bool used[N]; int main() {...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; set<pair<int, pair<int, int> > > all; int val[200005]; char str[200005]; int answer[200005][2], cnt, n; int second[4 * 200005]; void modify(int pos, int val, int id = 1, int l = 0, int r = n) { if (r - l < 2) { second[id] = val; return; } int mid = (l + r) >> ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; char seq[200005]; int ar[200005], nxt[200005], prv[200005]; bool vis[200005]; set<pair<int, int> > s; vector<pair<int, int> > ans; int main() { int n, i, x, px, ny; scanf("%d", &n); scanf("%s", seq); for (i = 0; i < n; i++) scanf("%d", &ar[i]); for (i = 0; i + 1 <...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct heap { int va, px, py; } d[201000]; int dtot, qq, n, a[201000], q[201000][2], nex[201000], la[201000]; char s[201000]; bool ex[201000]; bool operator<(heap x, heap y) { return (x.va < y.va || (x.va == y.va && x.px < y.px)); } void insert(int x, int y) { dtot++;...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.TreeSet; public class DancingLesson { class node implements Comparable<node> { int idx, val; ...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct parr { int w, pos1, pos2; }; bool operator<(const parr& a, const parr& b) { return a.w > b.w || (a.w == b.w && a.pos1 >= b.pos1); } int main() { priority_queue<parr> q; int n; int i, j; int num = 0; cin >> n; bool U[n]; int prev[n], next[n]; for (...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 220000; set<pair<int, int> > S; int a[N], prv[N], nxt[N]; char s[N]; int main() { int n; scanf("%i%s", &n, s + 1); for (int i = 1; i <= n; i++) scanf("%i", &a[i]); for (int i = 1; i <= n; i++) prv[i] = i - 1, nxt[i] = i + 1; for (int i = 1; i < n; i+...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import java.awt.Point; import java.io.*; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class ProblemC_K_3_ZKSH_2010_2011 { final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE")!=null; BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokeniz...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
from heapq import heappush,heappop,heapify n=int(input()) symbols=input() skl=list(map(int,input().split())) LMap=[i-1 for i in range(n+1)] RMap=[i+1 for i in range(n+1)] LMap[1],RMap[n]=1,n h=[] res=[] cnt=0 B=symbols.count("B") N=min(n-B,B) ind=[False]*(n+1) for i in range(n-1) : if symbols[i]!=symbols[i+1] : ...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int INF = 0x3f3f3f3f; char s[N]; int n, a[N], l[N], r[N], ans[N][2], vis[N]; struct node { int u, v, w; } tp; bool operator<(node p, node q) { if (p.w == q.w) return p.u > q.u; return p.w > q.w; } int ok(int a, int b) { return 1 <= a && a ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int maxN = 200 * 1000 + 5; const int mod = 1000 * 1000 * 1000 + 7; string s; set<int> se; set<pair<int, int> > an; int a[maxN]; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; cin >> s; for (int i = 0; i < n; i++) cin >> a[i], se.insert(...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int L[maxn], R[maxn], skill[maxn]; char s[maxn]; int n; bool vis[maxn]; struct node { int u; int v; int c; }; bool operator<(const node a, const node b) { if (a.c ^ b.c) return a.c > b.c; else return a.u > b.u; } priority_queue<nod...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int maxn = 200005; int SZ[maxn]; int K[maxn]; int LC[maxn]; int RC[maxn]; class SizeBalanceTree { public: void clear() { sz = 0; LC[0] = RC[0] = 0; SZ[0] = 0; root = 0; } int Size() { return SZ[root]; } bool empty() { return root == 0; } voi...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int n; string s; int a[200007]; int prv[200007]; int nxt[200007]; int used[200007]; struct tuhla { int diff; int l, r; }; bool operator<(struct tuhla p1, struct tuhla p2) { if (p1.diff != p2.diff) { return (p1.diff > p2.diff); } return (p1.l > p2.l); } priorit...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; inline void read() {} template <typename F, typename S> ostream &operator<<(ostream &os, const pair<F, S> &p) { return os << "(" << p.first << ", " << p.second << ")"; } template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os << "{"; typename v...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int a[200010]; char BG[200010]; int main() { memset(a, 0, sizeof(a)); priority_queue<pair<int, pair<int, int>>, vector<pair<int, pair<int, int>>>, greater<pair<int, pair<int, int>>>> pq; set<int> num; int n = 0; scanf("%d", &n); scanf("%s"...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq n=int(input()) g=input() a=[int(i) for i in input().split()] h=[] heapq.heapify(h) prev=[i-1 for i in range(0,n)] next=[i+1 for i in range(0,n)] d=[0]*n; r1=[] r2=[] r=[] for i in range(0,n-1): if(g[i]!=g[i+1]): heapq.heappush(h,(abs(a[i]-a[i+1]),i,i+1)) while h : aa,ii,jj=heapq.heappop(h) ...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct data { int x, y, d; data(int _x, int _y, int _d) { x = _x, y = _y, d = _d; } bool operator<(const data &b) const { if (d == b.d) { if (x == b.x) return y > b.y; return x > b.x; } return d > b.d; } }; string inp; int n, a[200010], v[200...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int Inf = 1000000000; const int Maxn = 200005; const int Maxm = 1048576; int n; char typ[Maxn]; int a[Maxn]; int L[Maxm], R[Maxm], I[Maxm]; int lef[Maxm], rig[Maxm]; vector<pair<int, int> > res; int Best(int v) { return min(min(L[v], R[v]), I[v]); } void Union(int v) ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string order; cin >> order; vector<int> a(n); for (int i = (0); i < ((n)); ++i) cin >> a[i]; set<pair<int, pair<int, int> > > pairs; map<pair<int, int>, int> pairDiff; for (int i = (0); i < ((n - 1)); ++i) if (order[i] != ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; char s[200011]; int a[200011]; int ans[100011][2]; int ll[200011], rr[200011]; int vis[200011]; int cnt; struct node { int l, r; int x; friend bool operator<(node a, node b) { if (a.x == b.x) return a.l > b.l; return a.x > b.x; } }; priority_queue<node> q; i...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
/** * Created by IntelliJ IDEA. * User: Taras_Brzezinsky * Date: 9/13/11 * Time: 5:33 PM * To change this template use File | Settings | File Templates. */ import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.IOException; import java.util.*; public class...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; set<pair<long long, pair<long long, long long> > > v; vector<pair<long long, long long> > ans; long long n, i, h[200010], g[200010], prv[200010], nxt[200010]; string s; int main() { cin >> n >> s; g[0] = g[n + 1] = 2; h[0] = -2 * 10000010; h[n + 1] = 2 * 10000010; ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
from heapq import heappush, heappop,heapify n = int(input()) b = list(input()) a = [int(i)for i in input().split()] c = [] d = [0]*n e = [] ahead = [0]+[i for i in range(n)] after = [i+1 for i in range(n)]+[0] num = 0 for i in range(n-1): x = i y = i+1 ...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; typedef struct couple { int a, b, w; } couple; bool operator<(const couple &a, const couple &b) { if (a.w == b.w) return a.a > b.a; return a.w > b.w; } couple build_couple(int a, int b, int w) { couple tmp; tmp.a = a; tmp.b = b; tmp.w = w; return tmp; } int ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct couple { int i1; int i2; int diff; bool operator<(const couple& other) const { if (diff > other.diff) return 1; else if (diff < other.diff) return 0; else { if (i1 > other.i1) return 1; else return 0; } ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; import java.util.Comparator; import java.util.LinkedList; import java.util.PriorityQueue; public class C45 { static StreamTokenizer in = new StreamTokenizer(new ...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
// practice with kaiboy import java.io.*; import java.util.*; public class CF45C extends PrintWriter { CF45C() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF45C o = new CF45C(); o.main(); o.flush(); } int[] aa, ll, rr; int[] pq, iq; int cnt; boolean lt(in...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") #pragma GCC target("popcnt,abm,mmx,tune=native") char sex[200010]; int val[200010]; int l[200010]; int r[200010]; struct node { int lpos; int rpos; int dis; bool operator<(const node &r) const { ret...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; long long BigMod(long long B, long long P, long long M) { long long R = 1; while (P > 0) { if (P % 2 == 1) { R = (R * B) % M; } P /= 2; B = (B * B) % M; } return R; } struct data { int dif, L, R; bool operator<(const data &a) const { if...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq as hq n=int(input()) l=input() A=[int(i) for i in input().split()] d=[] nxt=[i+1 for i in range(n-1)] frt=[i for i in range(n-1)] now=[True for i in range(n)] for i in range(n-1): if l[i]!=l[i+1]: d+=[[abs(A[i]-A[i+1]),i,i+1]] hq.heapify(d) ans=[] while d!=[]: a,b,c=hq.heappop(d) if (no...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
from heapq import * n = int(input()) que = input() skill = [int(i) for i in input().split()] difference = [] couple = [] left = [i - 1 for i in range(n)] right = [i + 1 for i in range(n)] for i in range(1, n): if que[i] != que[i-1]: heappush(difference, (abs(skill[i]-skill[i-1]), i-1, i)) while len(difference): d...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; long long min(long long a, long long b) { return a > b ? b : a; } int N, bnum, gnum; int L[500009], R[500009], sk[500009]; char bg[500009]; int P[500009]; struct node { long long key; int home; }; struct heap { int size; node s[500009]; void clear() { size = 0; } ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 222222; int ans[MAXN][10]; int n; int first[MAXN]; int behind[MAXN]; char str[MAXN]; bool mark[MAXN]; int a[MAXN]; struct node { int i, j; int d; bool operator<(node a) const { if (d != a.d) return d > a.d; return i > a.i; } node() {} no...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int n, m; int a[200010], b[200010]; int L[200010], R[200010]; char s[200010]; set<pair<int, int> > st; vector<pair<int, int> > ans; int h; void input() { scanf("%s", s); for (int i = 0; i < n; i++) b[i] = (s[i] == 'B' ? 1 : 2); for (int i = 0; i < n; i++) { L[i] =...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200000; pair<int, pair<int, int> > ms(int a, int b, int c) { return make_pair(a, make_pair(b, c)); } int x[N]; char s[N + 1]; bool viz[N]; int m = 0; int l[N], r[N]; int r1[N], r2[N]; priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int>...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int n, ka, ans[210010][7], a[210010], d, l[210010], r[210010]; pair<int, int> o; set<pair<int, pair<int, int> > > s; char c[210010]; set<pair<int, pair<int, int> > >::iterator it; pair<int, pair<int, int> > k; int abs(int a) { if (a >= 0) return a; return -a; } int main...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; string p; long long s[200007], l[200007], r[200007]; bool vis[200007]; struct couple { long long l, r, d; couple(long long l, long long r, long long d) : l(l), r(r), d(d) {} }; bool operator<(const couple &l, const couple &r) { if (l.d == r.d) return l.l > r.l; retu...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import java.io.*; import java.util.*; import java.math.*; public class Dancing { int L[] = new int[200001]; int R[] = new int[200001]; boolean isBoy[] = new boolean[200001]; int rating[] = new int[200001]; TreeSet<Pair> set = new TreeSet<Pair>(); Dancing() throws Exception { Scanner in...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq n=int(input()) g=input() a=[int(i) for i in input().split()] h=[] heapq.heapify(h) prev=[i-1 for i in range(0,n)] next=[i+1 for i in range(0,n)] d=[0]*n; r=[] for i in range(0,n-1): if(g[i]!=g[i+1]): heapq.heappush(h,(abs(a[i]-a[i+1]),i,i+1)) while h : aa,ii,jj=heapq.heappop(h) if(d[ii]...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int sayi_s; string str = "-"; string ph; priority_queue<pair<int, pair<int, int> > > pq; vector<pair<int, int> > komsular; vector<int> sayilar; int e_s, k_s; int main() { cin >> sayi_s; cin >> ph; str += (ph + "-"); sayilar.push_back(-1); for (int i = 1; i <= sayi...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; bool ch[200001]; struct info { long long df, l, r; }; struct cmp { bool operator()(const info& a, const info& b) { if (a.df == b.df) return a.l > b.l; return a.df > b.df; } }; int main() { ios_base::sync_with_stdio(0); long long int i, j, x, n, cnt = 0, m,...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int M = 300100; struct partners { int diff, l, r; partners(int a = 0, int b = 0, int c = 0) { diff = a; l = b; r = c; } bool operator<(const partners &d) const { if (diff == d.diff) return l > d.l; else return diff > d.diff; }...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import javax.swing.*; import java.io.*; import java.util.*; import java.util.stream.Collectors; import java.util.stream.IntStream; import java.util.stream.Stream; import java.util.Map.Entry; public class Main implements Runnable { static final int MOD = (int) 1e9 + 7; static final int MI = (int) 1e9; stati...
JAVA
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
from heapq import heapify, heappop, heappush n=int(input()) s=input() a=list(map(int,input().split())) p=[i-1 for i in range(n)] nx=[i+1 for i in range(n)] f=[1 for i in range(n)] d=[(abs(a[i]-a[i+1]),i,i+1) for i in range(n-1) if s[i]!=s[i+1]] heapify(d) ans=[] while d: t,pp,pn=heappop(d) if (f[pp] and f[pn])...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; assert(1 <= n && n <= (int)(2e5)); string sex; cin >> sex; assert(sex.size() == n); for (int i = 0; i < n; ++i) { assert(sex[i] == 'B' || sex[i] == 'G'); } vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i];...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; class Skill { public: int s, l, r; Skill(int _s, int _l, int _r) : s(_s), l(_l), r(_r) {} friend inline bool operator<(const Skill& o1, const Skill& o2) { if (o1.s != o2.s) return !(o1.s < o2.s); return !(o1.l < o2.l); } }; int main() { int n, i, j, i2, j...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
# It seems the running time depends much on the condition of the server. from heapq import heappush,heappop,heapify n=int(input()) symbols=input() skl=list(map(int,input().split())) LMap=[i-1 for i in range(n+1)] RMap=[i+1 for i in range(n+1)] LMap[1],RMap[n]=1,n h=[] res=[] cnt=0 #B=symbols.count("B") #N=min(n-B,B) in...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct P { int l, r, v; } o; bool operator<(const P &x, const P &y) { return x.v == y.v ? x.l > y.l : x.v > y.v; } priority_queue<P> q; bool u[N]; char s[N]; int a[N], L[N], R[N]; vector<pair<int, int> > r; int main() { int n, i; scanf("%d", &n...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; char tmp[200005]; int n; inline int abs(int n) { if (n > 0) { return n; } else { return -n; } } struct Node { int left, right; int skill; Node() {} Node(int l, int r, int s) { left = l; right = r; skill = s; } bool operator<(Node o) con...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq n = int(input()) line = str(input()) a = [int(i) for i in input().split()] diff = [] couples = [] left = [i-1 for i in range(n)] right = [i+1 for i in range(n)] for i in range(n-1): if line[i] != line[i+1]: heapq.heappush(diff,(abs(a[i]-a[i+1]),i,i+1)) while len(diff)>0: d,l,r = heapq.hea...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
# -*- coding: utf-8 -*- """ Created on Sat May 7 11:48:38 2016 @author: Alex """ import heapq, sys q = [] cnt = 0 n = int(input()) sex = input() a = list(map(int, input().split())) l = [i-1 for i in range(n)] #η”Ÿζˆε·¦ζŒ‡ι’ˆεˆ—θ‘¨ r = [i+1 for i in range(n)] #η”Ÿζˆε³ζŒ‡ι’ˆεˆ—θ‘¨ for i in range(n-1): if sex[i] != sex[i+1]: heapq.heappush(...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { return a == 0 ? b : gcd(b % a, a); } template <class T> string tostring(T a) { ostringstream os; os << a; return os.str(); } int toint(string a) { istringstream is(a); int p; is >> p; return p; } long long toll(string a) ...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 200010; struct node { int v, x, y; bool operator<(const node &b) const { return v > b.v || (v == b.v && min(x, y) > min(b.x, b.y)); } }; int a[N], pre[N], suc[N], ans[N][2], n; bool boy[N], out[N]; priority_queue<node> Q; char s[N]; int main() { sc...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct node { int x, y, d; bool operator<(const node &t) const { return (d > t.d) || ((d == t.d) && (x > t.x)); } } temp; int n, r[200005], x[200005], y[200005], X, Y, out, a[100005][2]; char s[200005]; bool b[200005]; priority_queue<node> q; int main() { scanf(...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; set<pair<int, int> > vset; vector<pair<int, int> > rvec; int a[N], n, pre[N], nxt[N]; char str[N]; int main() { scanf("%d", &n); scanf("%s", str); for (int i = 0; i < n; i++) scanf("%d", a + i); for (int i = 0; i < n; i++) { pre[i] = i - 1...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, t = 0, l, r, a[N], v[N], L[N], R[N]; char s[N]; struct cmp { bool operator()(pair<int, int> &r, pair<int, int> &q) const { if (abs(a[r.first] - a[r.second]) == abs(a[q.first] - a[q.second])) return r.first > q.first; return abs(...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq,sys q=[] c=0 n=int(input()) s=input() a=list(map(int,input().split())) l=[i-1 for i in range(n)] r=[i+1 for i in range(n)] for i in range(n-1): if s[i]!=s[i+1]: heapq.heappush(q,(abs(a[i]-a[i+1]),i,i+1)) c+=1 ans=[] while c>0: t,i,j=heapq.heappop(q) c-=1 if r[i]==-1 or r[j]==-1: continue ans.app...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
import heapq, sys q = [] cnt = 0 n = int(input()) sex = input() a = list(map(int, input().split())) l = [i-1 for i in range(n)] r = [i+1 for i in range(n)] for i in range(n-1): if sex[i] != sex[i+1]: heapq.heappush(q, (abs(a[i] - a[i+1]), i, i+1)) cnt += 1 ans = [] while cnt > 0: t, i, j = heapq.heappop(q) cnt -...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; string s; cin >> s; vector<int> v(n); vector<int> l(n, -1), r(n, -1); set<pair<int, pair<...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> std::mt19937 rng( (int)std::chrono::steady_clock::now().time_since_epoch().count()); const int ms = 200200; int a[ms]; bool dead[ms]; std::string str; struct Event { int i, j; Event(int a = -1, int b = -1) { i = a, j = b; } bool operator>(const Event &o) const { return std::pair<i...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; vector<pair<int, int> > v; set<pair<int, int> > s; int A[200005], L[200005], R[200005], n, i, a, b, c, d; char str[200005]; int main() { cin >> n >> str + 1; for (i = 1; i <= n; i++) { cin >> A[i]; R[i] = i + 1; L[i] = i - 1; if (i > 1 && str[i] != str[i...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; struct node { int ll; int y; int d; friend bool operator<(const node p, const node q) { if (p.d == q.d) return p.y > q.y; else return p.d > q.d; } } t; int l[200010]; int r[200010]; int b[200010]; int g[2]; int skill[200010]; int main() { cha...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#Code by Yijie Xia, submitted for testing the OJ import heapq as hq n=int(input()) s=input() a=list(map(int,input().split())) pre=[i-1 for i in range(n)] nxt=[i+1 for i in range(n)] free=[1 for i in range(n)] line=[(abs(a[i]-a[i+1]),i,i+1) for i in range(n-1) if s[i]!=s[i+1]] hq.heapify(line) ans=[] while line: t,...
PYTHON3
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; const int MAXN = 2 * 1e5 + 5; char s[MAXN]; int a[MAXN]; set<pair<int, int> > Q; set<int> S; vector<pair<int, int> > ans; int main() { int n; cin >> n; for (int i = 0; i < n; i++) cin >> s[i]; for (int i = 0; i < n; i++) S.insert(i); for (int i = 0; i < n; i++) ci...
CPP
45_C. Dancing Lessons
There are n people taking dancing lessons. Every person is characterized by his/her dancing skill ai. At the beginning of the lesson they line up from left to right. While there is at least one couple of a boy and a girl in the line, the following process is repeated: the boy and girl who stand next to each other, havi...
2
9
#include <bits/stdc++.h> using namespace std; set<pair<int, pair<int, int> > > dist; set<pair<int, int> > s; char c[222222]; int a[222222]; int n; int main() { scanf("%d", &n); scanf("%s", &c); int c1 = 0, c2 = 0; for (int(i) = 0; (i) < (n); ++(i)) { scanf("%d", &a[i]); if (c[i] == 'B') { s.insert...
CPP