import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* Created by Kamil Miekus on 25.11.2016.
*/
public class sze {
public static void main(String[] args) {
try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
String line = reader.readLine();
int[] timesA = new int[1_000_001];
int[] timesB = new int[1_000_001];
int[] timesC = new int[1_000_001];
int n = Integer.parseInt(line.split(" ")[0]);
int m = Integer.parseInt(line.split(" ")[1]);
int[][] times = new int[n][3];
int a, b, c;
int timeAMin = 0, timeBMax = 0;
int totalTime = 0;
for (int i = 0; i < n; i++) {
line = reader.readLine();
a = Integer.parseInt(line.split(" ")[0]);
b = Integer.parseInt(line.split(" ")[1]);
c = Integer.parseInt(line.split(" ")[2]);
timesA[a]++;
timesB[b]++;
timesC[c]++;
times[i][0] = a;
times[i][1] = b;
times[i][2] = c;
}
for (int i = 0; i < timesA.length; i ++) {
if (timesA[i] > m || timesB[i] > m) {
System.out.println("NIE\n");
return;
}
}
for (int i = 0; i < times.length; i++) {
if (i == 0) {
timeAMin = times[i][0];
timeBMax = times[i][1];
} else {
if (times[i][0] < timeAMin) {
timeAMin = times[i][0];
}
if (times[i][1] > timeBMax) {
timeBMax = times[i][1];
}
}
totalTime += times[i][2];
}
if (totalTime > (timeBMax - timeAMin) * m) {
System.out.println("NIE\n");
return;
}
System.out.println("TAK\n");
} catch (IOException e) {
e.printStackTrace();
}
}
}
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; /** * Created by Kamil Miekus on 25.11.2016. */ public class sze { public static void main(String[] args) { try(BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) { String line = reader.readLine(); int[] timesA = new int[1_000_001]; int[] timesB = new int[1_000_001]; int[] timesC = new int[1_000_001]; int n = Integer.parseInt(line.split(" ")[0]); int m = Integer.parseInt(line.split(" ")[1]); int[][] times = new int[n][3]; int a, b, c; int timeAMin = 0, timeBMax = 0; int totalTime = 0; for (int i = 0; i < n; i++) { line = reader.readLine(); a = Integer.parseInt(line.split(" ")[0]); b = Integer.parseInt(line.split(" ")[1]); c = Integer.parseInt(line.split(" ")[2]); timesA[a]++; timesB[b]++; timesC[c]++; times[i][0] = a; times[i][1] = b; times[i][2] = c; } for (int i = 0; i < timesA.length; i ++) { if (timesA[i] > m || timesB[i] > m) { System.out.println("NIE\n"); return; } } for (int i = 0; i < times.length; i++) { if (i == 0) { timeAMin = times[i][0]; timeBMax = times[i][1]; } else { if (times[i][0] < timeAMin) { timeAMin = times[i][0]; } if (times[i][1] > timeBMax) { timeBMax = times[i][1]; } } totalTime += times[i][2]; } if (totalTime > (timeBMax - timeAMin) * m) { System.out.println("NIE\n"); return; } System.out.println("TAK\n"); } catch (IOException e) { e.printStackTrace(); } } } |
English