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
n, m = map(int, raw_input().split()) for _ in xrange(n): s, f, t = map(int, raw_input().split()) s -= 1 f -= 1 init = 0 if s > f: s, f = m - 1 - s, m - 1 - f init = m - 1 if s == f: print t if s < f: if t <= s + init: print f + init e...
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 get_etag(long long t, long long m, bool& up) { long long mx = t % (2 * m - 2); if (mx <= (m - 1)) { return mx + 1; up = true; } up = false; return (2 * m - 2) - mx + 1; } pair<long long, long long> get_two_time(long long s_etag, long long 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
#include <bits/stdc++.h> using namespace std; int main() { int N, m; cin >> N >> m; for (int i = 0; i < N; ++i) { int s, f, t; cin >> s >> f >> t; if (s == f) { cout << t << "\n"; continue; } int t1; t1 = t; t %= (2 * m - 2); --s, --f; if (s < f) { if (t <= 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.util.*; import java.lang.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; public class A{ Scanner sc=new Scanner(System.in); int INF=1<<28; double EPS=1e-9; void run(){ long n=sc.nextLong(); long m=sc.nextLong()-1; 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
import java.util.*; import java.io.*; public class A { BufferedReader input; StringTokenizer token; int n,m; int getNext(int floor, int time) { floor--; int t = time/(2*m)*(2*m); if(t+floor >= time)return t+floor; else if(t+((2*m-floor)%(2*m)) >= time) return t+((2*m-floor)%(2*m)); else return t+floo...
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()) for i in range(n): s,f,t = map(int,raw_input().split()) if s == f: print t elif s > f: k = m-1 while t-k > m-s: k += 2*(m-1) print (m-f)+k else: k=0 while t+1-k > s: k += 2*(m-1) print 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> using namespace std; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int s, f, t, pb, pis, tr, ta; cin >> s >> f >> t; if (s == f) cout << t << endl; else { pb = (t / (m - 1)) % 2; pis = (t % (m - 1)); if (pb == 0) pis++; 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); for (int i = (int)0; i < (int)n; i++) { int si, fi, ti; scanf("%d %d %d", &si, &fi, &ti); if (si == fi) { printf("%d\n", ti); } else if (si < fi) { int period = ti / (2 * (m - 1)); int 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; const double eps = 1e-8; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { int s, t, aim; cin >> s >> aim >> t; if (aim == s) cout << t << endl; else if (aim > s) { int in = t / (2 * (m - 1)); int last = in * 2 * (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
#include <bits/stdc++.h> using namespace std; int main() { int n, m, s, t, f, m1; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) { scanf("%d%d%d", &s, &f, &t); m1 = 2 * (m - 1); if (s == f) printf("%d\n", t); else if (f > s) { if (t % m1 < s) { printf("%d\n", f + t / m1 * ...
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, md; int nx(int in, int floor) { int ans = in; int c = in % md, hz; if (c >= m - 1) { hz = (md - c); if (hz >= floor) ans += hz - floor; else ans += floor + hz; } else { if (c <= floor) ans += floor - c; 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 static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; p...
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; struct Peo { int s, f, t; bool operator<(const Peo &rhs) const { if (t != rhs.t) return t < rhs.t; if (s != rhs.s) return s < rhs.s; return f < rhs.f; } } aa; int main() { int n, m; while (cin >> n >> m) { for (int i = 0; i < n; ++i) { cin >>...
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 sys input = sys.stdin.readline n,m = map(int, input().split()) for _ in range(n): s,f,t = map(int, input().split()) floor = 1+(t%(2*m-2)) if t%(2*m-2)<m-1 else 2*m-1-t%(2*m-2) up = t%(2*m-2)<m-1 if(floor==s): time=0 elif(floor>s): if(up): time = (floor-s)+2*(m-flo...
PYTHON3
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
import java.io.*; import java.util.*; public class Elevator117A { public static void main(String[] args) throws IOException { BufferedReader f = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(f.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() { int n = 0; int m = 0; scanf("%ld %ld", &n, &m); while (n--) { int s = 0; int f = 0; int t = 0; int salida = 0; scanf("%ld %ld %ld", &s, &f, &t); if (s == f) { salida = t; } else { long T = 2 * (m - 1); --s; --f; sali...
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> #pragma comment(linker, "/STACK:16777216") using namespace std; template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); } const long double PI = 3.1415926535897932384626433832795; const long double EPS = 1e-9; void ASS(bool b) { if (!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.io.BufferedReader; import java.io.InputStreamReader; import java.util.StringTokenizer; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author zulkan */ public class lift { public static void main(String p[]) throws Exception { te...
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> long n, m, way, number, s, f, t, flag; int main() { scanf("%d %d", &n, &m); for (long i = 0; i < n; i++) { scanf("%d %d %d", &s, &f, &t); number = 0; way = 0; flag = 0; number = t % (2 * m - 2); if (number > (m - 1)) { way = 0; number = m - number % (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
import sys if __name__ == "__main__": (n, m) = map(int, raw_input().split()) for i in xrange(n): (s, f, t) = map(int, raw_input().split()) s -= 1 f -= 1 cy = 2 * (m - 1) if s == f or m == 1: print t elif s < f: print (t / cy) * cy + (0, cy...
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 main() { int i, j, n, m, d, m1, t, t1; vector<int> v; cin >> n >> m; int a[n], b[n], c[n]; m1 = m - 1; for (i = 0; i < n; i++) cin >> a[i] >> b[i] >> c[i]; for (i = 0; i < n; i++) { t1 = 0; if (b[i] == a[i]) v.push_back(c[i]); 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
#include <bits/stdc++.h> using namespace std; int n, m; int gao(int& lv, int& mv, int go) { int ret = 0; if (mv < 0) { if (go <= lv) { ret = lv - go; } else { ret = (go - 1) + (lv - 1); mv = -mv; } } else { if (go >= lv) { ret = go - lv; } else { ret = (m - lv) + ...
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()) mod = 2 * m - 2 for i in xrange(n): (s, f, t) = map(int, raw_input().split()) if s == f: print t continue s -= 1 f -= 1 offs = t % mod base = t - offs if s < f: if s < offs: base += mod print base + f else: s2 = m - 1 - s if m - 1 + s2 < offs: base += mod f2 ...
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 A_117_Elevators { public static void main(String[] args){ Scanner input=new Scanner(System.in); int n=input.nextInt(); long m=input.nextLong(); long[][] participants=new long[n][3]; long[] results=new long[n]; int i; long s,f,ti,t,result = 0; long p=(m-1)*2; fo...
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.*; import java.math.*; public class Main { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer tokenizer=null; public static void main(String[] args) throws IOException { new Main().execute(); } void debug(Object...os) { System.out...
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
L=raw_input() L=L.split() n=int(L[0]) m=int(L[1]) for i in range(n): In=raw_input() In=In.split() s=int(In[0]) f=int(In[1]) t=int(In[2]) if s==f: print t elif s<f: result=( (t-s)/((m-1)*2)+1)*(m-1)*2+f-1 print result else: result=((t-2*m+s)/((m-1)*2)+1)*(m...
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 sys import math ans = [] input = sys.stdin.readline n, m = map(int, input().strip().split()) for _ in range(n): start, end, t = map(int, input().strip().split()) start -= 1 end -= 1 if start == end: ans.append(t) continue if start < end: full = 2 * (m - 1) ans...
PYTHON3
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 gao(int s, int e, int t) { if (s == e) return t; int x = t / (2 * m); int r = t % (2 * m); if (r < m && r > s) return gao(s, e, 2 * m * x + m); if (r < m && s < e) return 2 * x * m + e; if (r < m && s > e) return 2 * x * m + m + (m - e); if (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> const long double pi = 3.1415926535897932384626433832795; const int INF = (int)1E9; const int MAXN = (int)11000; using namespace std; int main() { int n, m, a, b, c, t, cur, ans; bool dir; scanf("%d%d\n", &n, &m); for (int i = 0; i < (int)(n); i++) { scanf("%d%d%d\n", &a, &b, &c); ...
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 Elevator { public static void main( String[] args ) throws Exception { BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) ); String[] parts = br.readLine().split( " " ); int n = Integer.parseInt( parts[0] ); ...
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 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
#include <bits/stdc++.h> using namespace std; int main() { int m, n; cin >> n >> m; for (int i = 0; i < n; ++i) { int s, f, t; cin >> s >> f >> t; int per = (m - 1); int r = t / per; int k = t - r * per; if (f == s) { cout << t << endl; continue; } if (r % 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.util.*; public class A { public static void main(String[] args) { new A(new Scanner(System.in)); } // Returns new directions int[] countTime(int N, int src, int snk, int dir) { int[] res = new int[2]; res[1] = dir; // Move from sf to ef if (dir == 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
import java.io.*; import java.util.*; public class CA { String s = null; String[] ss = null; int n = 0; int m = 0; public void run() throws Exception{ BufferedReader br = null; File file = new File("input.txt"); if(file.exists()){ br = new BufferedReader(new FileReader("input.txt")); } else{ ...
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.FileNotFoundException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.PriorityQueue; import java.util.StringTokenizer; public class A { public static int[] x = {0, 1, 0, -1, 1, -1, 1, -1}; public static 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
#include <bits/stdc++.h> using namespace std; const long long int inf = 5 * (1e+8); const long long int mod = 1e+9 + 7; vector<long long int> adj[500005]; vector<long long int> visited(500005, 0); vector<long long int> t(500005, 0); long long int flag = 1; void nothing() {} void solve() { long long int n, m; cin >>...
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; long long h(long long t) { long long q = t / (M - 1); long long r = t % (M - 1); if (q % 2 == 0) return r + 1; else return M - r; } long long ttg(long long t, long long s) { long long h1 = h(t); long long dir = (t / (M - 1)) % 2; if (h1 == 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.InputStreamReader; import java.util.StringTokenizer; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ /** * * @author zulkan */ public class lift { public static void main(String p[]) throws Exception { te...
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.Arrays; import java.util.Scanner; public class elev { public static void debug(Object... obs) { System.out.println(Arrays.deepToString(obs)); } public static void main(String[]args) { Scanner sc = new Scanner(System.in); int n=sc.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
#include <bits/stdc++.h> int main() { int n = 0; int m = 0; scanf("%ld %ld", &n, &m); while (n--) { int s = 0; int f = 0; int t = 0; int output = 0; scanf("%ld %ld %ld", &s, &f, &t); if (s == f) { output = t; } else { long T = 2 * (m - 1); --s; --f; outp...
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.InputMismatchException; import java.math.BigInteger; import java.io.*; /** * Generated by Contest helper plug-in * Actual solution is at the bottom */ public class Main { public static void main(String[] args) { InputReader in = new StreamInputReader(System.in); PrintWriter out = new PrintWrit...
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 < N; i++) { int ini, fin, t; int cicl; cin >> ini >> fin >> t; if (ini == fin) { cout << t << endl; continue; } cicl = t / (2 * (m - 1)); if (ini < fin) { if (t % (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
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ //package topcoderjava; import java.io.*; /** * * @author hebaabdelnasser */ public class Elevator { public static void main(String[] args) throws IOException { BufferedReader data = new BufferedReader...
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.math.*; import java.io.*; public class LOL { public static void main(String[] args) throws Exception { Scanner in = new Scanner(System.in); int N = in.nextInt(); int M = in.nextInt(); int D = M+M-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
#include <bits/stdc++.h> int main() { int n = 0; int m = 0; scanf("%ld %ld", &n, &m); while (n--) { int s = 0; int f = 0; int t = 0; int salida = 0; scanf("%ld %ld %ld", &s, &f, &t); if (s == f) { salida = t; } else { long T = 2 * (m - 1); --s; --f; sali...
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 int inf = 0x7fffffff; const int Size = 1000 * 1000 + 1; char buffer[Size]; int solution(int nTest) { int m, n; scanf("%d%d", &n, &m); m--; int p = 2 * m; for (int i = 0; i < n; i++) { int s, f, t; scanf("%d%d%d", &s, &f, &t); f--; s--; 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
import java.io.*; import java.util.*; public class A117 { public static void main(String args[]) { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); String n1=""; try { n1=br.readLine(); } catch(IOException io) { System.out.println("error"); } StringTokenizer s1=new StringTokenizer(n1); long ...
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 a117 { public static void main(String[] Args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int m = sc.nextInt(); for(int k =0;k<n;k++){ int sfloor = sc.nextInt()-1; int efloor = sc.nextInt()-1; int time = sc.nextInt(); if(sfloor == efloor){ System...
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, i, j; cin >> n >> m; int s, f, t; for (i = 0; i < n; i++) { cin >> s >> f >> t; if (f == s) { cout << t << endl; continue; } if (f > s) { j = floor(float(t - s + 1) / (2 * m - 2)); if ((t - 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
import java.io.IOException; import java.util.Scanner; public class A117 { public static void main(String args[]) throws IOException { Scanner sc = new Scanner(System.in); int n = sc.nextInt(), m = sc.nextInt(), z = 2*m - 2, s = 0, f = 0, t = 0, k = 0; for (int i = 1; i < n+1; i ++){ s = sc.nextInt(); 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
import java.util.*; import static java.lang.Math.*; import java.io.*; public class A { public static void main(String[] args) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer stok = new StringTokenizer(in.readLine()); int N = Integer.valueOf(stok.nextTok...
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, ans, a, b, c, d, e, g; cin >> n >> m; while (n--) { cin >> s >> f >> t; if (s == f) { cout << t << "\n"; continue; } s--; f--; ans = t - t % (2 * m - 2); t = t % (2 * m - 2); if (t <= 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 main() { int i, n, m; int s, f, t; while (scanf("%d%d", &n, &m) != -1) { m--; for (i = 1; i <= n; i++) { scanf("%d%d%d", &s, &f, &t); if (s == f) { printf("%d\n", t); continue; } s--; f--; int tm = t % (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, s, f, t, bot, top, curr, dir, ans; scanf("%d%d", &n, &m); bot = 1; top = m; while (n--) { scanf("%d%d%d", &s, &f, &t); if (s == f) { ans = t; } else { if ((t / (m - 1)) % 2 == 0) { dir = 1; } else { dir = 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 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 if (s < f) { int z = (t - s + 2 * (m - 1)) / (2 * (m - 1)); printf("%d\n", ab...
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.Arrays; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; public class A { public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public...
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
from sys import stdin,stdout a,b=map(int,stdin.readline().split()) ans=2*(b-1) ok=[0]*a for i in range(a): x,y,z=map(int,stdin.readline().split()) if x==y:ok[i]=(z) elif x<y: if z<x:ok[i]=y-1 else:ok[i]=ans*((z+ans-x)//ans)+y-1 else: k=b-1 x=b+1-x y=b+1-y ...
PYTHON3
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.*; public class A implements Runnable { void solve() { int n = nextInt(); int m = nextInt(); for (int i = 0; i < n; i++) { int s = nextInt() - 1; int f = nextInt() - 1; int t = nextInt(); if (s == f) { out.println(t); continue;...
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 readAB(): s = raw_input() i = s.index(' ') return int(s[:i]), int(s[i+1:]) def readABC(): s = raw_input() i = s.index(' ') j = s[i+1:].index(' ') return int(s[:i]), int(s[i+1:i+j+1]), int(s[i+j+2:]) def doIt(s,f,t): if s == f: return t elif s < f: wait = t % (2 * (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
n, m = map(int, input().split()) k = 2 * (m - 1) ans = [] for _ in range(n): s, f, t = map(int, input().split()) d = t % k if s < f: ad = (k if s <= d else 0) + f - 1 + t - d elif f < s: ad = (k if d + s > k + 1 else 0) + k + 1 - f + t - d else: ad = t ans.append(ad) prin...
PYTHON3
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 Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int m = in.nextInt(); int n = in.nextInt(); for (int i = 0; i < m; i++) { int x = in.nextInt() - 1; int y = in.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
import sys # f = open('p1.2.in','r') # read = lambda: f.readline().strip() read = lambda: sys.stdin.readline().strip() def get_floor(i): i %= cycle_length if i <= m-1: return [i+1,i,1] else: return [m-(i-m)-1,i,-1] n,m = map(int,read().split(' ')) cycle_length = 2*m-2 for i in xrange(n):...
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 main() { int n, i; long int m; scanf("%d%ld", &n, &m); for (i = 0; i < n; i++) { long int s, f, t, lop, ft; scanf("%ld%ld%ld", &s, &f, &t); lop = (m - 1) * 2; ft = t % lop; int up = 1; if (ft >= (lop / 2)) up = -1; if (s != 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
import java.io.PrintWriter; import java.util.Locale; import java.util.Scanner; public class A implements Runnable { private Scanner in; private PrintWriter out; private void solve() { int n = in.nextInt(); int m = in.nextInt(); for (int i = 0; i < n; ++i) { int s = in.n...
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 N, M; int F(int s, int f, int t) { if (f == s) return t; int a = t / (M - 1), b = t % (M - 1); int ft; if (a % 2 == 0) { ft = 1 + b; if (ft <= s) { t += s - ft; if (f >= s) return t + f - s; else return t + 2 * M - 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
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.io.PrintWriter; import java.math.BigInteger; import java.util.*; public class A88 { static boole...
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() { long int n, m, s, f, t, c, k; char a, b; scanf("%ld%ld", &n, &m); while (n--) { scanf("%ld%ld%ld", &s, &f, &t); if (s == f) printf("%ld\n", t); else { if (s < f) a = '+'; else a = '-'; if ((t / (m - 1)) % 2 == 0) c...
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; void solve() { cin >> n >> m; for (int i = 0; i < n; ++i) { int s, f, t, fulls, dir, curr_fl; cin >> s >> f >> t; if (s == f) { cout << t << endl; 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
#include <bits/stdc++.h> using namespace std; int main() { int n, m; int t1[100005]; cin >> n >> m; for (int i = 0; i < n; i++) { int st, fin, t; cin >> st >> fin >> t; if (st == fin) { t1[i] = t; continue; } int tst = st - 1; if (st > fin) tst = 2 * m - 2 - tst; if (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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * User: Samuel * Date: 09-23-11 * Time: 09:03 AM */ public class A { public static void main(String[] args) throws IOException { new A().run(); } private int m; private void run() throws IOEx...
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 a, b, c; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < (int)(n); i++) { scanf("%d%d%d", &a, &b, &c); if (a == b) printf("%d\n", c); else { int l; if (a < b) { l = c / (2 * m - 2); l *= 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
import java.io.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String[] S = in.readLine().split(" "); int n = Integer.parseInt(S[0]); int m = Integer.parseInt(S[1]); long round = 2 * (m - 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 < n; i++) { int s, f, t; cin >> s >> f >> t; if (s == f) { cout << t << endl; continue; } s--; f--; int tresta = t % (m - 1); int rebots = t / (m - 1); if (rebots %...
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 Template implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); void init() throws FileNotFoundException { try { in = new BufferedReader(new FileReader("input.txt")); o...
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, x, y, t, k, p, i; scanf("%d%d", &n, &m); for (i = 0; i < n; i++) { scanf("%d%d%d", &x, &y, &t); if (m == 1 || x == y) printf("%d\n", t); else { if (t == 0) k = 0; else k = (t - 1) / (m - 1); p ...
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 { public static void main(String[] args) throws IOException { // TODO Auto-generated method stub BufferedReader r=new BufferedReader(new InputStreamReader(System.in)); String s=r.readLine(); String[] sp=s.split(" "); int n=new Integer(sp[0]); int m=new...
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.awt.geom.Point2D; import java.text.*; import java.math.*; import java.util.*; public class Main implements Runnable { final String filename = ""; public void solve() throws Exception { int n = iread(), m = iread(); for (int nn = 0; nn < n; nn++) { int s = iread(), f = iread(),...
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 N = 100000; const int M = 100000000; int main() { int n, m; int s, f, t; scanf("%d %d", &n, &m); int x = 2 * (m - 1); for (int i = 1; i <= n; i++) { scanf("%d %d %d", &s, &f, &t); if (s == f) printf("%d\n", t); else { int ans = ab...
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, i; cin >> n >> m; int s[n], f[n], t[n]; int k, r; for (i = 0; i < n; i++) { cin >> s[i] >> f[i] >> t[i]; k = (t[i] - 1) / (m - 1); if (t[i] == 0) k = 0; if (f[i] == s[i]) { cout << t[i] << endl; 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
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a % b); } void solve() { long long int n, m; cin >> n >> m; long long int strt[n + 3], ends[n + 3], time[n + 3]; for (long long int i = 0; i < n; i++) { cin >> strt[i] >> ends[i] >> tim...
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, i, s, f, t, tp, j; cin >> n >> m; for (i = 0; i < n; ++i) { cin >> s >> f >> t; j = 0; if (s == f) cout << t << endl; else { tp = s - 1; if (tp < t) { j = (t - tp) / (2 * (m - 1)); tp += 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> using namespace std; inline bool equal(double _x, double _y) { return _x > _y - 1e-9 && _x < _y + 1e-9; } int main() { int n, m, s, f, t, tp; scanf("%d%d", &n, &m); m = 2 * m - 2; while (n--) { scanf("%d%d%d", &s, &f, &t); if (s == f) { 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.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Task117A { public static void main(String... args) throws NumberFormatException, IOException { Solutio...
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; public class Aorangy1 { /** * @param args */ static int m; static long f(long v, int floor) { if(floor == 1){ return (v-1)*(m-1)*2; } if(floor == m){ return (m-1)+((v-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> int n, m; int calcup(int s, int f) { if (s <= f) { return f - s; } return (m - s) + (m - f); } int calcdown(int s, int f) { if (s >= f) { return s - f; } return (s - 1) + (f - 1); } int main() { scanf("%d%d", &n, &m); for (int i = 0; i < n; i++) { int s, f, t; sc...
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.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.io.StreamTokenizer; public class A implements Runnable { int m; public void solve() throws IOException { int n = nextInt(); m = nextInt() - 1; 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
/* * 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
#include <bits/stdc++.h> using namespace std; int m; int main() { int n; scanf("%d%d", &n, &m); int mod = (m - 1) * 2; --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; } --s, --f; int q = t / mod; in...
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.InputStreamReader; import java.util.StringTokenizer; public class Elevator { void run() { try { BufferedReader bfd = new BufferedReader(new InputStreamReader( System.in)); StringTokenizer tk = new StringTokenizer(bfd...
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; struct sd { long long s, f, tim, pos; } num[1000000]; long long ans[1000000]; int main() { int n, m; while (cin >> n >> m) { for (int i = 0; i < n; i++) { cin >> num[i].s >> num[i].f >> num[i].tim; num[i].pos = i; } int cir = 2 * (m - 1); 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 main() { ios ::sync_with_stdio(false); int n, a, b, t, m; cin >> n >> m; for (int i = 0; i < (int)(n); i++) { cin >> a >> b >> t; a--, b--; if (a == b) { cout << t << "\n"; continue; } int col = t / (m - 1); bool up = col % 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 int INF = INT_MAX; const double EPS = 1e-10; inline double SQR(double x) { return x * x; } inline long long SQR(long long x) { return x * x; } inline int SQR(int x) { return x * x; } inline double SQR3(double x) { return x * x * x; } inline void DEBUG() { puts("jackie...
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
s=raw_input().split() n=int(s[0]) m=int(s[1])-1 for i in range(n): s=raw_input().split() ini=int(s[0])-1 fin=int(s[1])-1 t=int(s[2]) if ini==fin: r=t elif ini<fin: r=ini while r<t: r+=2*m r+=fin-ini else: r=2*m-ini while r<t: ...
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 n, m; int cal(int s, int f, bool up) { int ans = 0; if (f > s) { if (up) ans = f - s; else ans = s - 1 + f - 1; } else { if (!up) ans = s - f; else ans = m - s + m - f; } return ans; } int main() { scanf("%d%d", &n, &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
import java.io.IOException; import java.io.OutputStreamWriter; import java.io.BufferedWriter; import java.util.InputMismatchException; import java.io.OutputStream; import java.io.PrintWriter; import java.util.NoSuchElementException; import java.io.Writer; import java.math.BigInteger; import java.io.InputStream; /** *...
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, f, t; int ret(int s, int t) { int tt = s - 1; while (tt < t) tt += 2 * (m - 1); return tt; } int ret2(int s, int t) { int tt = -s + 1; while (tt < t) tt += 2 * (m - 1); return tt; } int main() { cin >> n >> m; for (int i = 0; i < n; 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.io.*; import java.util.StringTokenizer; public class A { BufferedReader in; StringTokenizer str; PrintWriter out; String SK; String next() throws IOException { while ((str == null) || (!str.hasMoreTokens())) { SK = in.readLine(); if (SK == null) return null; str = new Stri...
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 fd(int tt, int k) { int t = tt; t %= m + m - 2; if (t < m) { if (k >= t) { return tt + k - t; } else { return tt + m * 2 - t - k - 2; } } else { t -= m; t = m - t - 2; if (k <= t) { return tt + t - k; } els...
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.*; import java.math.*; import java.io.*; import static java.lang.Math.*; import static java.util.Arrays.*; // Elevator // 2011/9/24 public class P117A{ Scanner sc=new Scanner(System.in); void run(){ long n=sc.nextLong(); long m=sc.nextLong()-1; for(int i=0; i<n; i++){ ...
JAVA