summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/NetworkPacket.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/NetworkPacket.java b/src/main/NetworkPacket.java
new file mode 100644
index 0000000..805dcf5
--- /dev/null
+++ b/src/main/NetworkPacket.java
@@ -0,0 +1,83 @@
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Scanner;
+
+public class NetworkPacket {
+
+ public static class Request {
+ public int arrivalTime;
+ public int processTime;
+
+ public Request(int arrivalTime, int processTime) {
+ this.arrivalTime = arrivalTime;
+ this.processTime = processTime;
+ }
+
+ }
+
+ public static class Response {
+ public boolean dropped;
+ public int startTime;
+
+ public Response(boolean dropped, int startTime) {
+ this.dropped = dropped;
+ this.startTime = startTime;
+ }
+ }
+
+ public static class Buffer {
+ private int size;
+ private ArrayList<Integer> finishTime = new ArrayList<Integer>();
+
+ public Buffer(int size) {
+ this.size = size;
+ }
+ public Response processRequests(Request request) {
+ // write your code here
+ if (this.size == 0)
+ return new Response(false,-1);
+ else {
+ if (finishTime.size() == 0)
+ }
+ }
+ }
+ private static ArrayList<Request> ReadQueries(Scanner scanner) throws IOException {
+ int requests_count = scanner.nextInt();
+ ArrayList<Request> requests = new ArrayList<Request>();
+ for (int i = 0; i < requests_count; ++i) {
+ int arrival_time = scanner.nextInt();
+ int process_time = scanner.nextInt();
+ requests.add(new Request(arrival_time, process_time));
+ }
+ return requests;
+ }
+
+ public static ArrayList<Response> processRequests(ArrayList<Request> requests, Buffer buf) {
+ ArrayList<Response> responses = new ArrayList<>();
+ for (int i = 0; i < requests.size(); i++) {
+ responses.add(buf.processRequests(requests.get(i)));
+ }
+ return responses;
+ }
+ private static void PrintResponses(ArrayList<Response> responses) {
+ for (int i = 0; i < responses.size(); ++i) {
+ Response response = responses.get(i);
+ if (response.dropped) {
+ System.out.println(-1);
+ } else {
+ System.out.println(response.startTime);
+ }
+ }
+ }
+
+ public static void main(String[] args) throws IOException {
+ Scanner scanner = new Scanner(System.in);
+
+ int buffer_max_size = scanner.nextInt();
+ Buffer buffer = new Buffer(buffer_max_size);
+
+ ArrayList<Request> requests = ReadQueries(scanner);
+ ArrayList<Response> responses = processRequests(requests, buffer);
+ PrintResponses(responses);
+ }
+}