Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- /* run this program using the console pauser or add your own getch, system("pause") or input loop */
- int max(int a, int b) {
- if (a < b)
- return b;
- return a;
- }
- int main(void) {
- int n, m, t[100]={0}, a[100]={0}, t0=0, res[100]={-1}, bol=1;
- scanf("%d%d", &n, &m);
- for(int i=0; i<n; i++) {
- scanf("%d%d", &t[i], &a[i]); --a[i];
- res[i] = -1;
- }
- while(bol!=0) {
- bol=0;
- int min=-1;
- for(int i=0; i<n; i++) {
- if(res[i] == -1 && (min == -1 || t[i]<t[min])) {
- min=i;
- }
- }
- t0=max(t0, t[min])+a[min];
- for(int i=0; i<n; i++) {
- if(res[i] == -1 && a[min]>=a[i]&&t0+a[min]>=t[i]+a[i]) {
- res[i]=t0+a[min];
- }
- }
- t0+=a[min];
- for(int j=0; j<n; j++) {
- if(res[j]==-1) {
- bol=1;
- }
- }
- }
- for(int i=0; i<n; i++) {
- printf("%d\n", res[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement