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
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.util.StringTokenizer; public class Q117A implements Runnable { private void solve() throws IOException { int n = nextInt(); int m = nextInt(); for (int i = 0; i < n; i++) { int s = nextInt(); int f = nextInt(); int t = nextIn...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; const int INF = (int)2E9; const long long LINF = (long long)9E18; const long double PI = acos(-1.0); const long double EPS = 1E-11; int main() { bool ok; long long n, m, s, t, f, res; cin >> n >> m; for (int i = 0; i < (n); ++i) { cin >> s >> f >> t; if (s =...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.util.Arrays; import java.util.StringTokenizer; public class Solver { public stati...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import sys std_input = sys.stdin n, m = map(int, std_input.readline().split()) #print(n,m) for i in range(n) : s,f,t = map(int, std_input.readline().split()) #print(s,f,t) added = t//(2*(m-1))*(2*(m-1)) t %= 2*(m-1) if s < f : if t > s-1 : print(added+2*(m-1)+f-1) else...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.Scanner; public class P117A { public static void main(String[] args) { Scanner inScanner = new Scanner(System.in); int n = inScanner.nextInt(); int m = inScanner.nextInt(); for (int i = 0; i < n; i++) { int s = inScanner.nextInt(); int f = ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
n,m = map(int, raw_input().split()) per = 2*m - 2 for i in range(n): s,f,t = map(int, raw_input().split()) if s == f: print t elif s < f: wait = (t - s + per) / per print per * wait + f - 1 else: st = m - 1 + m - s wait = (t - st + per - 1) / per print per...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Main * * @author alper * @since 23.09.2011 */ public class Main { public static void main(String[] args) { final Scanner scanner = new Scanner(new BufferedInputStream(Sy...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m; int s[100001], f[100001], t[100001]; int main() { int i, j, k, t1, ans; scanf("%d %d", &n, &m); for (i = 1; i <= n; i++) { scanf("%d %d %d", &s[i], &f[i], &t[i]); if (s[i] == f[i]) { printf("%d\n", t[i]); continue; } k = t[i] % (2...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.math.*; import java.util.*; import java.util.List; import java.util.Queue; import java.awt.*; public class codefors implements Runnable { private BufferedReader br = null; private PrintWriter pw = null; private StringTokenizer stk = new StringTokenizer(""); public static...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; public class elevator { public static void main(String args[]) { Scanner in = new Scanner(System.in); int n = in.nextInt(), m = in.nextInt(); int len = 2*(m-1); for(int i = 0; i < n; ++i) { int s = in.nextInt()-1, f = in.nextInt()-1, t = in.nextInt();...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; import java.io.*; public class a { public static void main(String[] args) throws IOException { //Scanner input = new Scanner(new File("input.txt")); //PrintWriter out = new PrintWriter(new File("output.txt")); PrintWriter out = new PrintWriter(System.out); input.init(System.in);...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int gao(int n, int k, int t) { int m = 2 * (n - 1); int x = t / m * m; int y = t % m; if (k >= 1 + y) { x += k - 1; } else if (k <= n - (y - (n - 1))) { x += (n - 1) + (n - k); } else { x += m + k - 1; } return x; } int main() { int n, m, a, b, c; scanf("%d%d", &...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import javax.sound.sampled.Line; import java.awt.Point; import java.awt.geom.Line2D; import java.awt.geom.Point2D; import java.io.*; import java.math.BigInteger; import static java.math.BigInteger.*; import java.util.*; public class A{ void solve()throws Exception { int n=nextInt(); long m=next...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
def g(f, t, m): x = max((t - f) / (2 * m) + 1, 0) y = max((t + f - 2) / (2 * m), 0) return min(2 * m * x + f - 1, 2 * m * y + 2 * m + 1 - f) n, m = map(int, raw_input().split()) for s, f, t in [map(int, raw_input().split()) for _ in xrange(n)]: print [g(f, g(s, t, m - 1), m - 1), t][s == f]
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; public class A117 { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = null; private void solution() throws IOExceptio...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import sys def solve(): n, m = map(int, sys.stdin.readline().split()) for case in xrange(n): res = 0 s, f, t = map(int, sys.stdin.readline().split()) if s == f: res = t print res continue e = 0 up = 1 if t % (2*(m-1)) < m -1: ...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; long long solve(long long s, long long f, long long t, long long m) { if (s == f) return t; long long p = (m - 1) * 2; long long x = t / p * p; if (s < f) x += s - 1; else x += 2 * m - 1 - s; return (x < t ? x + p : x) + (f > s ? f - s : s - f); } int ma...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; struct person { long s; long f; long t; long t_fin; }; int main() { long n, m; cin >> n >> m; vector<person> people(n); for (long i = 0; i < n; i++) cin >> people[i].s >> people[i].f >> people[i].t; for (long i = 0; i < n; i++) { if (people[i].s == peo...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, f, t; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> s >> f >> t; if (s == f) { cout << t << "\n"; continue; } int trem = t % (2 * (m - 1)); int tdiv = t / (2 * (m - 1)); int geton; if (t - trem + ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> const int maxi = 2000000000; const int maxq = 1000000000; const double eps = 1e-10; const double pi = 3.1415926535897932; const double inf = 1e+18; const int mo = 1000000007; using namespace std; int l[111111], r[111111], t[111111], n, m, p; int main() { scanf("%d%d\n", &m, &n); for (int i ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); long long zq; zq = (m - 1) * 2; for (int i = 0; i < n; i++) { int s, t, time; scanf("%d%d%d", &s, &t, &time); long long num, ans; num = (time - 1) / zq; if (num < 0) num = 0; if (s == t) { ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m; int main() { int s, f, t, i, e, ans; cin >> n >> m; for (i = 1; i <= n; ++i) { cin >> s >> f >> t; if (s not_eq f) { e = t % (2 * (m - 1)); ans = t; if (e < m) { ++e; if (s >= e) { ans += s - e; i...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.Scanner; public class Prob117A { public static void main( String[] Args ) { Scanner scan = new Scanner( System.in ); int peo = scan.nextInt(), floor = scan.nextInt(); for ( int x = 0; x < peo; x++ ) { int s = scan.nextInt(), f = scan.nextInt(), t = ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.math.*; import java.util.*; /*public class TaskA { } */ public class TaskA implements Runnable { // based on Petr's template private void solve() throws IOException { int n = this.nextInt(); int m = this.nextInt(); int M = ( m - 1 ) * 2; for ( int i = 0; i < n; i ++ ){ int s...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.IOException; import java.io.InputStream; import java.util.InputMismatchException; public class P117A_Elevator { /** * @param args */ public static void main(String[] args) { InputReader reader = new InputReader(System.in); int n = reader.nextInt(); int m = reader.nextInt(); int[][] data =...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> bool DEBUG = false; using namespace std; int n, m, s[100000], f[100000], t[100000]; int next(int start_time, int level) { int current_level = start_time % (2 * m - 2) + 1; if (current_level <= m) { if (current_level <= level) return start_time + level - current_level; else ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; public class cf117a { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int m = in.nextInt(); for(int i=0; i<n; i++) { int s = in.nextInt()-1; int f = in.nextInt()-1; int t = in.nextInt(); if(s > f) { s = 2*m-2-s; f = 2*...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#!/usr/bin/env python n,m = map(int, raw_input().strip().split()) cycle = (m*2-2) for i in xrange(n): s,f,t = map(int,raw_input().strip().split()) res = 0 if s==f: res = t; else: mod = t%cycle if s<f: earliest = s-1 if mod <= earliest: res = earliest+(f-s) else: res = earliest+(f-s)+cycle ...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> inline int Time(int a, int b, int m) { return (b < a) ? 2 * m - 2 + b - a : b - a; } inline int min(int a, int b) { return (a < b) ? a : b; } inline int mirror(int a, int m) { return m - 1 - (a - m + 1); } inline int state(int t, int m) { return t % (2 * m - 2); } int main() { int n = 0; ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int dr[] = {1, 0, -1, 0, -1, -1, 1, 1}; int dc[] = {0, -1, 0, 1, -1, 1, -1, 1}; const int MAX = 500 + 7; const int MOD = 1e9 + 7; int main() { int n, m; cin >> n >> m; for (long long i = 0; i < n; ++i) { int s, e, t; cin >> s >> e >> t; if (s == e) { ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; public class A117 { public static void main(String args[]){ Scanner input = new Scanner(System.in); int n = input.nextInt(); int m = input.nextInt(); for(int i = 0; i<n ; i++){ int s = input.nextInt(); int f = input.nextInt(); int t = input.nextInt(); if (s==f) Syste...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Mohamed */ public class Main { public static void main(String[] arg...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b)...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); int person = input.nextInt(); int floor = input.nextInt(); int[] start = new int[person]; int[] end = new int[...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
s = raw_input().split(' ') n,m = int(s[0]),int(s[1]) for i in range(n): s = raw_input().split(' ') s,f,t = int(s[0]),int(s[1]),int(s[2]) if s == f: print t elif s > f: k = m-1 if (t-k > m-s): while t-k > m-s: k += 2*(m-1) print (m-f) + k ...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int abs(int a) { if (a >= 0) return a; else return -a; } int main() { int n, m; scanf("%d %d", &n, &m); int time[100000]; for (int i = 0; i < n; i++) { int s, f, t; scanf("%d %d %d", &s, &f, &t); if (s == f) { time[i] = t; } else if...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int n, m; int a, b, c; int now; bool dir; int main() { while (~scanf("%d%d", &n, &m)) { while (n--) { scanf("%d%d%d", &a, &b, &c); if (a == b) { printf("%d\n", c); continue; } if ((c / (m - 1)) % 2) { now = m - c % (m - 1); dir = 1; ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.util.*; public class A { BufferedReader br; PrintWriter out; StringTokenizer st; boolean eof; void solve() throws IOException { int n = nextInt(); int m = nextInt() - 1; for (int i = 0; i < n; i++) { int s = nextInt() - 1; ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = (0); i < ((int)(n)); i++) { int s, f, t; scanf("%d%d%d", &s, &f, &t); if (s == f) { cout << t << endl; continue; } s--; f--; int v = t % (m + m - 2); int S = s; if (S < ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; struct elevator_state { int floor; int direction; int t; static int floors; elevator_state(int t) { this->floor = t % (2 * (floors - 1)); this->direction = +1; this->t = t; if (this->floor >= floors) { this->floor = 2 * (floors - 1) - this->f...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf("%d%d", &n, &m); while (n--) { int a, b, t, ans; scanf("%d%d%d", &a, &b, &t); if (a == b) { printf("%d\n", t); continue; } int d = t / (m - 1); ans = d * (m - 1); if (d % 2 == 0) { if (ans + a - ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; public class c117A { private final Scanner sc; private static final boolean debug = true; static void debug(Object ... objects) { if(debug) System.err.println(Arrays.toString(objects)); } c117A() { sc = new Scanner(System.in); }...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
def g(f, t, m): x = max((t - f) / (2 * m) + 1, 0) y = max((t + f - 2) / (2 * m), 0) return min(2 * m * x + f - 1, 2 * m * y + 2 * m + 1 - f) n, m = map(int, raw_input().split()) for s, f, t in [map(int, raw_input().split()) for _ in range(n)]: print [g(f, g(s, t, m - 1), m - 1), t][s == f]
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main(void) { int n, m; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { int s, f, t; scanf("%d %d %d", &s, &f, &t); if (s == f) { printf("%d\n", t); continue; } int _t = t; t %= ((m - 1) * 2); bool up; if (t >= m - 1) { if (t - m ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) throws java.lang.Exception { MyScanner sc = new MyScanner()...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { int s, f, t; scanf("%d%d%d", &s, &f, &t); if (s == f) printf("%d\n", t); else { int tm = t % (m - 1), tt = t / (m - 1); int cur = 0; if (tt % 2 == 0) ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.util.*; import java.math.*; public class Main { private BufferedReader in; private PrintWriter out; private StringTokenizer st; private Random rnd; public void solve() throws IOException { int n = nextInt(), m = nextInt(); int cycle = m + m - 2; for(int i = 0; i < n; i+...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; bool down(int t, int m) { return (t - 1) / (m - 1) % 2; } int main() { int n, m, s, f, t, h; while (cin >> n >> m) { while (n--) { cin >> s >> f >> t; int a = s - 1, b = f - 1; if (t == 0) { if (a < b) cout << b << endl; e...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; /** * Author - * User: kansal * Date: 9/23/11 * Time: 9:41 PM */ public class CF88A { public static void main(String[] args) { reader = new BufferedReader(new InputStreamReade...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main(int argc, char **argv) { int n, m; cin >> n >> m; for (int i = 0; i < n; ++i) { int s, f, t; cin >> s >> f >> t; int tm = t % (2 * m - 2); if (s == f) { cout << t << endl; } else if (f >= s) { if (s - 1 >= tm) { cout <<...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; public class A { static class Parser { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Parser(InputStream in) { din = new DataInputStream(in); ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main() { int c, tt, n, x, y, z, m; while (scanf("%d%d", &n, &m) == 2) { while (n--) { scanf("%d%d%d", &x, &y, &z); if (x == y) { printf("%d\n", z); continue; } int k = 2 * m - 2; int a = z / k; int b = z % k; if (b >= m - 1) ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.math.BigInteger; import java.util.*; import com.sun.org.apache.bcel.internal.generic.ARRAYLENGTH; public class CodeForces { public void solve() throws IOException { int n = nextInt(); int m = nextInt() - 1; for (int i = 0; i < n; i++) { int s = nextInt() - 1; int f = nextIn...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.Scanner; public class Elevator { /** * @param args */ static long getWait(long curFloor, long endFloor, boolean up, long m) { if(up) { if(curFloor <= endFloor) return endFloor - curFloor; else return 2*(m - curFl...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Scanner; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintW...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, s, f, t, m, k, ans; int main() { scanf("%d %d\n", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d %d %d\n", &s, &f, &t); if (s == f) ans = t; else if (s < f) { k = max(int(ceil(1.0 * (t - s + 1) / 2 / (m - 1))), 0); ans = s - 1 + 2...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; const long double eps = 1e-8; struct pt { long double x, y; pt() {} pt(long double _x, long double _y) : x(_x), y(_y) {} pt operator+(const pt &p) const { return pt(x + p.x, y + p.y); } pt operator-(const pt &p) const { return pt(x - p.x, y - p.y); } pt operator...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author Mohamed */ import java.util.InputMismatchException; import java.math.BigInteger; import java.io.*; /** * Generated by Contest helper plug-in * Actual solution is at the bottom */ public class Ma...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import operator n, m = map(int, raw_input().split()) par = (tuple(map(int, raw_input().split())) for i in xrange(n)) mod = 2 * m - 2 def calc(s, f, t): offs = t % mod base = t - offs if s == f: return t if s < f: if s < offs: base += mod return base + f s2 = ...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigDecimal; import java.math.BigInteger; import java.util.StringTokenizer; public class Main { public static void main(String[] args)// throws FileNotFoundException { InputReader in=new InputRead...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-11; int main() { int N, M; int a, b, r, si, ei, ti; scanf("%d %d", &N, &M); for (int i = 0; i < N; i++) { scanf("%d %d %d", &si, &ei, &ti); si--; ei--; if (si == ei) { printf("%d\n", ti); ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int getint(void) { int v = 0, c; while (isdigit(c = getchar())) v = 10 * v + c - '0'; return v; } int tf(int m, int t, int x) { int te = t % (2 * (m - 1)), e = m - abs(te - m + 1); if (te < m - 1 && e <= x || te >= m - 1 && e >= x) return abs(e - x); else if (te < m - 1) ret...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main() { int i, n, m, a, b, flag, start, t; while (scanf("%d%d", &n, &m) != EOF) { for (i = 1; i <= n; i++) { scanf("%d%d%d", &a, &b, &t); if (a == b) { printf("%d\n", t); continue; } if (a == 1) { start = 0; while (start < t) ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m, s, f, t; int deal() { int tt, t1, t2, mm = m - 1; if (s == f) return t; else { if ((t / mm + 1) % 2 == 0 || t % (mm + mm) == 0) { if (t % (mm + mm) == 0) tt = 1; else tt = m - (t % mm); if (tt >= s) { t1 = t ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m; int vremyadoetazha(int s, int t) { int M = m - 1; int step = t / M; int napr = (step % 2) ? 1 : 0; int etazhNaT = 0; if (napr) { etazhNaT = M - t % M; } else { etazhNaT = t % M; } int wremya = t; if (!napr) { if (etazhNaT <= s) { ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.lang.*; import java.math.BigInteger; import java.io.*; import java.util.*; public class Solution implements Runnable{ public static BufferedReader br; public static PrintWriter out; public static StringTokenizer stk; public static boolean isStream = true; public static void main(String...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; import java.io.*; import java.math.*; import java.awt.geom.*; public class Elevator{ static int ppl,top; public static int solve(int floorCount,int from,int to,int time){ if (from == to) return 0; floorCount--; time%=2*floorCount; if(from<to) { if(time<=from-1) ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; long long n, m; int nap; int put(int x, int y, int napr) { if (x == y) { nap = napr; return 0; } if (napr == 0) { if (x > y) { nap = 1; return m - x + m - y; } else { nap = 0; return y - x; } } else { if (x > y) { ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < n; ++i) { int v, u, t; scanf("%d%d%d", &v, &u, &t); if (u == v) printf("%d\n", t); else { int ans = 0; if (v < u) { while (ans + v - 1 < t) ans += 2 * m - 2; ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main() { int n, m, i; scanf("%d %d", &n, &m); for (i = 0; i < n; i++) { int s, f, t; scanf("%d %d %d", &s, &f, &t); if (s == f) { printf("%d\n", t); } else if (s < f) { int x = t % (2 * m - 2); int y = t / (2 * m - 2); if (x < s) { print...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int n, m; void solve() { scanf("%d %d", &n, &m); for (int i = 0; i < n; ++i) { int s, f, t, fulls, dir, curr_fl; scanf("%d %d %d", &s, &f, &t); if (s == f) { printf("%d\n", t); continue; } fulls = t / (m - 1); dir = fulls % 2; if (dir) curr_fl =...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.Scanner; public class Elevator { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int participants = sc.nextInt(); long floors = sc.nextInt(); long states = floors*2-2; for (int i = 0; i < participants; i++) { ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, f, t; cin >> n >> m; for (int i = 0; i < n; i++) { scanf("%d%d%d", &s, &f, &t); int sign = (t - 1) / (m - 1), ans = 0, now; if (t == 0) sign = 0; if (sign % 2 == 0) { now = (t % (m - 1)); if (!now) now = m - 1; ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n >> m; for (long long i = 1; i <= n; i++) { long long s, f, t; cin >> s >> f >> t; if (s == f) { cout << t << endl; } else if (s < f) { long long t1 = s - 1; while (t1 < t) { t1 += (m - s) ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m; int main() { cin >> n >> m; while (n--) { int s, f, t, sum, k; cin >> s >> f >> sum; if (s == f) { cout << sum << endl; continue; } if (s < f) t = s - 1; else t = 2 * (m - 1) - (s - 1); sum -= t; if (sum ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
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.io.Reader; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; impo...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.util.*; public class Elevator { public static void main(String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(in.readLine()); int n = Integer.parseInt(st.nextToken()); int m = Integ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main(void) { int nPart, m, i, s, f, t, k, fin; scanf("%d %d", &nPart, &m); int tiempo[nPart]; for (i = 1; i <= nPart; i++) { scanf("%d %d %d", &s, &f, &t); if (s == f) { tiempo[i] = t; } else if (s < f) { k = 0; fin = 0; while (!fin) { if ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int ans; int s, f, t; scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d %d %d", &s, &f, &t); int tmp = t % (2 * m - 2); if (t % (2 * m - 2) < m - 1) { if (s - 1 >= tmp) { if (f >= s) ans = t ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; struct T { int x, y, r; T(int X = 0, int Y = 0, int R = 0) : x(X), y(Y), r(R * R) {} int dist(T p) { return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y); } bool operator<(const T& p) const { if (x == p.x) return y < p.y; else return x < p.x; }...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
n, m = map(int, raw_input().split()) m -= 1 for i in xrange(n): s, f, t = map(int, raw_input().split()) s -= 1 f -= 1 if s == f: print t continue base = t / (2*m) * (2*m) t %= (2*m) if t <= s: st = s if f < s: et = m + m - f else: et = f elif t <= m + m - s: st = ...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main() { int n, m; scanf("%d%d", &n, &m); m = (m - 1) << 1; while (n--) { int s, f, t; scanf("%d%d%d", &s, &f, &t); --s; --f; if (s != f) { int q = t % m; t += ((s - f) < 0 ? -(s - f) : s - f); if (s > f) s = m - s; t += s - q + ((s < q) ?...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : (-x); } template <class T> T sqr(T x) { return x * x; } int calc(int s, int t, long long m) { int x = t / (2 * (m - 1)) - 2; x = max(x, 0); long long res = (long long)(1E18); for (int k = x; k <= x + 8; ++k) { ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, f, t, j; cin >> n >> m; int st[n]; for (int i = 0; i < n; i++) { cin >> s >> f >> t; j = t / (2 * (m - 1)); if (f - s > 0) { if (t > 2 * (m - 1) * j + s - 1) { st[i] = 2 * (m - 1) * (j + 1) + s - 1 + (f - s); ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
n, m = map(int, raw_input().strip().split()) for i in range(n): s, f, t = map(int, raw_input().strip().split()) if s == f: print t elif s > f: k = m-1 while t-k > m-s: k = k + 2*(m-1) print m - f + k else: k=0 while t+1-k > s: k = ...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int m; int when(int a, int b) { b--; a = a % (m * 2 - 2); if (a < m - 1) { if (a <= b) { return b - a; } return m - 1 - a + m - 1 - b; } a = 2 * m - 2 - a; if (a >= b) { return a - b; } return a + b; } int main() { int n; cin >> n >...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; import java.math.*; import java.util.*; public class A { final static int MOD = 1000000007; public static void main(String[] args) throws Exception { FastReader in = new FastReader(System.in); int n = in.nextInt(); int m = in.nextInt(); for (int i = 0; i < n; i++) { long s = in.nextLong();...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.PrintWriter; import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = in.nextInt(); int m = in.nextInt(); for (int i = 0; i < n; i++...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
n,m = map(int, str(raw_input()).split()) while n: n-=1 s,f,t = map(int, str(raw_input()).split()) if s==f: print t continue x = 2*(m-1) result = t-t%x t %= x if(t <= s-1): flag = True elif(t<= x-s+1): flag = False else: result += x flag...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String[] tokens = reader.readLine().split(" "); int n = Integer.parseInt(tokens[0]), m = Integer.parseInt(tokens[...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.Scanner; import java.lang.Math.*; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); int n = scan.nextInt(); // # participants int m = scan.nextInt(); // # floors for (int i = 1; i <= n; i++) { int s = scan.nextInt(); // start f...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { int total, top, start, final, time, i; cin >> total >> top; while (total > 0) { --total; cin >> start >> final >> time; if (final != start) { if (final > start) { for (i = 0; 2 * i * (top - 1) + (start - 1) < time; ++i) ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
def g(f, t, m): x = max((t - f + 1 + 2 * m - 3) / (2 * m - 2), 0) y = max((t - m * 2 + 1 + f + 2 * m - 3) / (2 * m - 2), 0) return min((2 * m - 2) * x + f - 1, (2 * m - 2) * y + m * 2 - 1 - f) n, m = map(int, raw_input().split()) print '\n'.join(`[g(f, g(s, t, m), m), t][s == f]` for s, f, t in [map(int, raw_input(...
PYTHON
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; template <typename T> inline void checkmin(T &a, T b) { if (a > b) a = b; } const int N = 100000; int s[N], f[N], t[N]; int n, m; void getres() { int s, f, t; scanf("%d %d %d", &s, &f, &t); int res = 0; int a1 = (m - 1); int a2 = (a1 << 1); int b = t / a2; i...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { vector<long long> vs, vt, vf; long long n, m, i, j, a, b, ma = -1, c, k = 1, p; cin >> n >> m; for (i = 0; i < n; i++) { cin >> a >> b >> c; if (a == b) cout << c << endl; else { long o = 2 * m - 2; j = c % o; if (j >...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> int main() { unsigned long int n, m, s, f, t, floor, time; while (scanf("%lu %lu", &n, &m) != EOF) { while (n--) { scanf("%lu %lu %lu", &s, &f, &t); if ((t / (m - 1)) % 2 == 1) { floor = m - (t % (m - 1)); } else if ((t / (m - 1) % 2 == 0)) { floor = 1 ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, n, m, x, y, z, tr, c1, c2; bool h; cin >> n; cin >> m; for (i = 0; i < n; i++) { cin >> x; cin >> y; cin >> z; if (x == y) { cout << z << endl; continue; } if (z / (m - 1) % 2) h = false; ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class ProblemA { public static void main(String[] args) throws IOException { BufferedReader stdin = ...
JAVA
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
#include <bits/stdc++.h> using namespace std; int n, m; int main() { scanf("%d%d", &n, &m); for (int(i) = 0; (i) < (n); ++(i)) { int st, fn, t; scanf("%d%d%d", &st, &fn, &t); --st; --fn; int eps = t / (2 * (m - 1)) * (2 * (m - 1)); if (st == fn) { printf("%d\n", t); continue; ...
CPP
117_A. Elevator
And now the numerous qualifying tournaments for one of the most prestigious Russian contests Russian Codec Cup are over. All n participants who have made it to the finals found themselves in a huge m-floored 108-star hotel. Of course the first thought to come in a place like this is "How about checking out the elevator...
2
7
import java.util.*; import java.lang.*; public class Elevator { public static void main(String arg[]) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); for(int k = 0;k<n;k++){ int s = sc.nextInt(); int f = sc.nextInt(); int t = sc.nextInt(); int total ...
JAVA