Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <stdio.h>
- #include <stdint.h>
- #include <new.h>
- #include <math.h>
- void main() {
- int num_of_req, reqs_per_sec;
- int time;
- int index = 0;
- int current_requests = 1;
- int max_requests = 1;
- int* timestamps;
- if(scanf("%d %d", &num_of_req, &reqs_per_sec) == 2) {
- }
- timestamps = (int*)malloc(num_of_req * sizeof(int));
- if(scanf("%d", &time) == 1) {
- }
- timestamps[0] = time;
- for (int i = 1; i < num_of_req; i++) {
- if (scanf("%d", &time) == 1) {
- }
- timestamps[i] = time;
- current_requests++;
- if (timestamps[index] + 1000 <= timestamps[i]){
- index++;
- current_requests--;
- }
- if (current_requests > max_requests) {
- max_requests = current_requests;
- }
- }
- printf("max req: %d \n", max_requests);
- printf("reqs per sec: %d \n", reqs_per_sec);
- float servers_required = ceil((float)max_requests / (float)reqs_per_sec);
- printf("%d", (int)servers_required);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement