50055. Waiting Time at Supermarket

難度:2/5

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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <limits.h>

int n, m;
int t, s;

int counter[1024] = {0};

int main(){
scanf("%d %d", &n, &m);

long long ans = 0;
for(int i = 0; i < m; i++){
scanf("%d %d", &t, &s);

int min_time = INT_MAX, min_idx;
for(int j = 0; j < n; j++){
if(counter[j] < min_time){
min_time = counter[j];
min_idx = j;
}
}
if(min_time <= t){
counter[min_idx] = s + t;
}
else{
ans += (min_time - t);
counter[min_idx] += s;
}
}
printf("%lld\n", ans);
}


50055. Waiting Time at Supermarket
https://aaronlin1229.github.io/judgegirl_50055/
Author
Akizumi
Posted on
July 17, 2023
Licensed under