## 11958 - Coming Home

Moderator: Board moderators

muhitsarwar
New poster
Posts: 1
Joined: Sat Nov 09, 2013 4:32 am

### 11958 - Coming Home why wrong ans!

#include<stdio.h>
#include<math.h>
int main()
{
long long int test,bus,tm,min;
long long int ch,cm,ah,am;
long long int i,j,l,a,b,c,d;
scanf("%lld",&test);
for(i=1;i<=test;i++)
{
scanf("%lld %lld:%lld",&bus,&ch,&cm);

min=1440;
for(j=1;j<=bus;j++)
{
scanf("%lld:%lld %lld",&ah,&am,&tm);
if(ch>ah) ah+=24;
else if(ch==ah&&am<cm) ah+=24;
b=am-cm;
a=(ah-ch)*60+tm+b;

if(min>a)
min=a;
}
printf("Case %lld: %lld\n",i,min);
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11958 - Coming Home

Input:

Code: Select all

``````1
1 18:00
17:59 1000``````
AC output:

Code: Select all

``````Case 1: 2439
``````
Check input and AC output for thousands of problems on uDebug!

reza_cse08
New poster
Posts: 8
Joined: Sun Nov 17, 2013 9:55 pm

### Re: 11958 - Coming Home

why I get wrong answer .................

#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

int main()
{
unsigned long long int aa[1000], n, t, bf, bf1, af, af1, i, a, temp, time, m;
char c;

t =0;
cin>>n;
while(n!=0)
{
t++;
cin>>a;
cin>>bf1>>c>>af1;
temp = bf1*60 + af1;

//cout<<bf<<" "<<af;
m =0;
for(i = 0;i<a;i++)
{
cin>>bf>>c>>af>>time;

if((bf*60 + af)<(bf1*60 + af1))
{
bf = 24+bf;
}
aa = (bf*60 + af + time) - temp;
//m = aa[0];
if(i>0)
{
m = min(aa,aa[i-1]);
}
else if(a==1)
{
m = aa[0];
}
}
cout<<"Case "<<t<<": "<<m<<endl;
memset(aa, 0,sizeof(aa));
n--;
}

return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11958 - Coming Home

Try input:

Code: Select all

``````1
3 18:00
18:01 1
17:58 1000
17:59 1000
``````
Check input and AC output for thousands of problems on uDebug!

sabah
New poster
Posts: 1
Joined: Sun Dec 08, 2013 12:54 pm

### Re: uva 11958

wa, but, all 100 test cases are right.

Code: Select all

``````#include <cstdio>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
long long int T, i, j, bus, curr_hr, curr_min, bus_hr[500], bus_min[500], bus_tym[500], cnt=0, res[500], diff;

scanf("%lld", &T);
for(i=1; i<=T; i++)
{
cnt++;
scanf("%lld %lld:%lld", &bus, &curr_hr, &curr_min);

for(j=0; j<bus; j++)
{
scanf("%lld:%lld %lld", &bus_hr[j], &bus_min[j], &bus_tym[j]);

res[j] = 60 - curr_min + bus_min[j] + bus_tym[j];
diff = (bus_hr[j] - curr_hr - 1);

if(diff < 0) diff += 24;
diff *= 60;

if((curr_hr == bus_hr[j]) && (curr_min < bus_min[j]))
{
diff=0;
res[j] -= 60;
}

res[j] += diff;
}

sort(res, res+bus);
printf("Case %lld: %lld\n", cnt, res[0]);
}

return 0;
}
``````

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: uva 11958

Input:

Code: Select all

``````100
16 14:10
15:36 823
05:13 176
02:01 554
07:27 483
12:23 300
03:24 738
09:03 811
23:04 728
04:38 922
17:34 360
15:13 852
05:46 925
13:36 107
08:32 705
10:12 521
22:55 784
1 16:27
19:03 152
14 12:01
18:05 321
17:00 328
17:18 559
22:07 222
16:31 924
13:58 838
13:32 550
17:32 782
12:44 51
11:09 105
04:52 325
00:09 766
20:30 629
07:16 400
3 20:01
21:01 886
20:42 71
18:47 2
2 11:32
00:50 875
10:23 846
7 11:35
06:47 328
12:22 306
17:44 800
22:17 825
13:05 280
05:12 571
09:25 841
10 13:44
02:28 262
04:26 600
19:36 894
08:16 775
10:33 82
17:36 122
01:29 39
15:46 766
21:43 82
15:04 39
12 23:38
02:19 901
16:06 585
21:50 115
17:41 893
22:58 240
08:27 353
03:58 685
03:20 545
16:35 804
02:26 334
05:08 292
09:04 748
11 13:44
06:07 822
04:05 236
22:05 787
18:12 444
20:39 468
05:35 319
19:50 621
00:43 945
16:32 580
22:02 110
11:21 311
1 05:39
00:08 162
15 14:57
15:22 988
12:27 453
08:03 480
02:07 193
04:00 803
22:38 275
22:53 34
04:26 43
08:14 543
08:20 505
17:00 685
22:24 628
06:01 827
12:07 925
05:00 595
15 02:59
02:36 231
11:29 428
18:01 721
20:09 587
05:07 779
15:33 144
09:03 3
06:19 977
15:12 387
11:58 815
10:41 61
07:32 437
17:18 587
18:07 673
11:48 741
5 07:44
09:17 546
20:27 906
14:06 359
12:06 90
04:56 993
10 03:06
03:25 979
14:35 649
07:22 377
22:38 538
19:47 760
02:43 869
01:25 478
03:53 875
04:34 262
14:55 251
18 11:57
02:17 423
02:12 913
18:11 899
17:46 526
18:00 487
18:05 760
16:21 729
01:37 520
06:20 575
14:09 19
04:23 750
16:53 821
07:27 281
19:32 290
23:54 703
15:24 426
08:45 508
22:10 729
4 04:06
15:10 426
18:42 431
22:39 435
19:22 815
20 17:07
21:33 145
00:24 725
00:20 84
17:58 719
07:53 961
18:00 370
21:54 601
20:45 765
23:52 394
18:12 768
05:13 412
18:13 194
12:01 183
03:58 799
08:34 559
17:16 111
13:13 92
07:25 634
16:53 556
15:03 138
20 08:59
17:38 619
10:15 335
04:46 710
12:31 470
17:40 388
11:41 580
04:52 478
17:00 206
23:19 270
13:19 87
01:24 493
10:58 593
08:06 471
21:54 845
08:00 674
03:15 20
12:43 483
14:53 208
09:44 588
07:22 701
14 03:50
13:25 78
21:49 29
15:11 373
12:47 667
21:03 21
16:55 912
20:57 970
16:54 441
19:49 465
06:54 92
00:55 632
05:44 729
17:15 782
07:51 260
14 01:51
02:53 239
23:29 487
09:09 192
16:05 315
00:27 252
12:39 878
04:33 783
10:06 130
03:13 763
00:38 45
03:44 308
18:08 723
01:33 189
19:53 985
14 18:45
14:58 3
18:50 335
14:49 214
18:56 323
10:00 18
10:04 632
04:46 764
04:03 73
17:58 694
23:12 708
12:30 970
16:40 730
10:42 789
01:37 237
19 03:22
08:49 705
03:06 517
22:26 639
03:59 571
01:58 10
09:26 209
15:10 44
15:36 990
05:42 483
19:40 359
09:00 973
20:20 632
04:46 59
20:53 825
15:34 912
01:19 129
18:50 482
02:58 303
09:39 189
2 02:20
04:35 834
13:55 932
12 04:11
00:04 745
23:55 607
13:33 816
04:19 28
22:01 977
21:15 138
01:36 751
10:57 219
23:14 557
12:25 353
23:49 866
20:25 44
5 14:56
15:58 646
04:25 703
04:50 680
10:03 750
11:29 343
12 16:03
10:28 888
02:44 219
02:56 944
01:40 972
10:07 123
05:00 880
14:08 544
14:10 686
07:33 770
20:44 317
04:31 642
13:49 262
4 15:01
11:16 63
12:30 976
00:00 450
21:30 773
9 13:52
19:20 890
15:56 964
19:28 931
20:21 525
17:25 231
23:40 164
09:16 537
14:57 374
12:58 688
6 15:31
05:02 296
23:21 684
17:40 132
06:13 150
08:42 336
01:57 634
19 18:27
14:33 744
02:37 559
13:14 73
20:36 283
08:23 648
04:04 174
04:10 505
14:22 592
17:47 427
16:17 75
00:24 201
16:14 565
23:55 9
21:08 618
21:04 970
22:32 337
04:52 722
02:43 958
03:04 966
15 13:17
11:37 328
17:53 282
20:09 462
09:06 95
07:40 98
19:54 225
16:46 918
02:05 326
11:32 167
18:58 73
03:25 750
12:18 320
00:06 344
11:04 895
18:39 944
14 10:16
08:54 345
23:33 67
02:32 897
01:30 261
13:46 615
14:34 780
12:02 699
00:05 73
14:59 831
04:32 631
08:16 810
07:56 471
03:22 882
08:23 78
8 12:39
23:30 815
06:06 36
04:18 715
01:12 637
22:28 899
21:53 727
14:04 37
13:08 848
16 04:11
20:47 992
11:38 457
05:21 111
17:53 300
18:18 916
11:16 283
17:53 850
11:12 340
09:37 823
21:32 884
08:21 784
15:48 519
00:29 487
07:10 458
13:57 124
00:48 699
12 09:00
23:08 578
03:41 164
12:02 832
08:26 967
04:29 539
14:33 55
13:53 860
05:22 739
15:22 949
02:13 76
03:40 851
07:56 997
14 00:19
23:12 653
18:28 239
09:10 887
10:47 398
14:04 383
14:20 136
07:34 252
10:41 578
17:53 836
21:46 157
20:37 808
14:55 259
01:28 342
13:31 231
4 01:04
15:31 620
01:15 631
13:25 230
10:10 304
11 23:47
11:24 653
20:14 415
09:55 843
09:00 62
01:23 243
21:18 815
13:08 414
11:49 428
19:11 87
20:02 388
19:13 384
8 21:10
10:34 587
06:32 300
12:13 574
04:58 173
19:51 853
01:26 244
08:10 928
17:54 427
6 18:40
22:57 846
20:56 521
22:18 960
08:42 392
21:22 895
05:33 777
18 22:48
23:18 874
08:03 311
07:29 71
23:51 187
20:15 72
23:37 260
03:49 122
07:15 284
02:12 558
07:50 359
11:49 804
01:21 981
14:20 657
20:59 837
04:07 938
00:18 858
14:49 585
11:09 385
19 03:11
22:02 884
09:02 368
19:51 192
20:17 783
14:30 349
15:26 427
11:03 227
09:29 20
01:20 888
23:58 724
02:49 996
19:38 754
17:45 491
04:05 898
11:07 46
21:26 124
22:26 583
14:35 992
15:28 164
10 20:10
06:14 207
13:10 376
19:31 382
16:48 517
18:03 816
23:25 807
18:51 736
04:41 841
03:36 708
11:45 721
11 03:19
01:57 980
07:04 167
11:56 755
00:42 834
20:53 444
15:39 703
20:19 526
21:51 245
02:50 126
19:52 204
18:54 544
13 01:17
09:04 691
06:04 957
06:17 364
00:08 726
09:57 316
23:18 125
18:32 7
11:43 347
23:13 660
20:05 392
13:50 237
18:00 400
05:47 78
3 11:20
07:08 373
19:59 946
22:54 813
16 17:42
17:28 831
09:40 963
03:17 875
17:59 323
11:20 831
23:15 532
11:22 129
04:53 148
07:31 525
06:06 75
04:16 3
03:01 853
08:32 522
20:01 702
20:25 349
23:52 517
14 15:54
07:35 599
20:06 954
08:28 383
04:32 545
17:23 789
01:08 195
19:20 694
23:08 683
12:19 241
08:04 447
02:47 983
05:11 173
15:11 141
20:16 271
17 13:20
18:02 470
17:33 376
09:01 124
14:53 235
23:18 240
07:36 959
02:42 849
15:57 815
12:21 624
21:18 589
05:40 944
14:01 208
18:22 86
23:00 307
10:39 696
18:58 564
12:24 511
15 07:23
16:59 334
21:08 829
00:38 452
01:28 779
11:50 194
15:01 999
00:04 815
15:10 778
06:50 872
20:25 267
07:57 488
19:42 493
14:10 296
17:23 57
21:47 534
17 06:23
20:30 477
03:01 491
16:23 779
06:19 878
20:30 984
21:18 339
06:00 916
22:17 654
17:54 454
03:31 92
03:51 495
10:34 428
04:30 75
12:05 327
09:13 365
19:38 903
15:36 769
3 22:23
17:28 691
10:31 410
18:50 571
4 01:57
10:53 961
00:29 838
13:42 648
01:29 569
8 20:44
13:55 138
12:52 211
10:18 775
02:12 679
02:56 399
11:30 427
07:10 231
20:15 999
11 17:15
10:16 471
07:30 121
18:58 697
21:36 342
19:03 148
00:45 993
14:32 922
01:32 391
21:04 419
19:07 989
14:09 763
3 16:20
16:14 267
23:23 172
04:47 948
10 11:27
23:42 569
22:35 814
08:33 735
09:08 981
19:59 190
21:13 695
22:53 705
09:44 429
00:12 954
23:14 337
11 13:40
10:47 301
02:43 230
03:56 453
02:51 60
11:37 524
05:35 655
09:36 842
20:16 114
03:39 623
13:22 359
09:56 626
1 15:05
01:42 340
3 20:53
22:24 901
15:17 518
17:42 3
17 02:34
04:57 876
17:50 373
12:23 352
18:56 935
03:09 856
17:03 476
15:37 987
01:04 391
15:09 465
08:38 948
06:42 791
00:27 23
03:03 621
03:01 195
10:05 357
11:02 869
01:53 480
19 23:11
01:54 299
09:14 2
20:01 10
21:53 255
00:20 478
14:04 612
17:42 852
16:06 847
19:47 170
22:25 415
10:54 789
23:04 605
18:40 153
23:49 310
07:13 829
07:08 61
01:37 943
23:41 707
12:24 831
8 15:13
16:17 579
00:32 440
22:30 831
01:53 233
09:00 49
09:48 902
14:25 294
01:40 966
15 05:06
22:40 156
23:00 943
19:48 369
03:10 509
12:51 992
02:52 143
21:26 441
13:28 807
17:33 472
19:47 284
14:49 723
15:12 274
02:36 345
20:03 923
09:07 157
7 21:40
04:55 981
18:36 839
01:41 497
01:29 42
05:23 305
06:30 585
19:08 151
1 17:47
08:38 292
5 08:32
12:53 549
06:59 908
20:05 371
23:58 215
05:39 913
17 13:43
03:32 898
07:25 878
18:21 378
16:05 772
12:21 510
19:51 724
18:39 220
11:18 852
00:27 903
01:03 94
20:55 393
11:30 833
12:00 645
14:16 369
01:57 984
17:04 160
01:51 736
14 14:27
04:26 999
14:43 413
13:51 35
21:43 17
02:59 493
13:25 754
13:39 111
06:24 805
23:49 740
20:35 979
11:55 45
09:21 235
11:10 475
04:48 664
12 14:25
02:55 589
10:44 164
06:19 295
19:30 326
03:42 166
01:29 358
14:55 494
02:18 978
09:03 273
00:54 523
01:45 370
04:35 566
11 05:15
13:17 109
05:56 354
20:26 723
22:20 215
09:22 935
10:07 915
00:11 553
12:49 963
19:17 968
03:08 990
18:37 832
9 18:15
00:42 315
05:40 290
10:41 154
01:03 383
07:19 639
07:07 602
21:07 861
09:10 959
19:21 501
19 21:36
22:09 443
19:42 56
05:44 838
12:33 73
19:04 109
02:12 776
09:33 134
14:34 441
03:46 167
21:16 42
09:54 491
19:14 545
01:19 492
12:31 884
07:43 707
09:21 132
14:06 194
03:09 860
02:28 428
11 14:05
15:39 903
13:47 738
13:36 907
18:49 945
05:12 543
12:21 31
23:51 631
11:06 273
09:08 226
22:18 370
15:37 518
15 14:28
20:44 664
00:50 244
04:07 309
03:23 658
23:58 65
18:09 358
09:23 665
09:33 845
23:40 247
05:54 55
21:06 503
10:35 81
00:51 366
14:31 371
05:46 921
9 16:09
05:42 541
18:51 901
02:03 157
04:56 214
04:09 808
16:20 846
18:08 963
16:39 80
06:12 540
7 16:51
15:09 104
00:32 707
09:14 222
11:54 788
23:46 278
17:18 666
11:37 194
13 05:08
12:39 641
22:45 280
01:01 832
14:41 959
07:18 195
02:33 791
22:20 488
07:30 792
00:45 472
17:49 585
18:13 503
07:27 525
04:33 859
4 23:34
18:58 196
00:13 257
04:27 895
18:58 915
12 14:38
09:11 603
05:41 3
20:16 976
08:45 493
02:00 40
16:43 323
13:07 255
12:51 314
19:49 778
04:21 311
18:54 800
13:03 105
6 03:24
04:52 684
09:10 447
13:02 739
07:32 134
03:20 424
05:31 787
3 23:37
20:09 644
18:02 887
10:19 932
11 03:30
15:00 317
16:01 322
01:21 205
08:04 605
11:37 725
03:51 860
04:36 482
15:54 504
10:20 1000
01:10 563
19:01 379
13 10:52
03:23 279
22:35 943
17:22 862
23:25 432
20:57 347
02:01 716
14:15 713
09:16 520
23:40 509
10:52 128
07:23 807
12:09 989
14:06 477
10 09:10
03:41 439
02:47 258
23:05 785
20:54 568
04:41 676
22:20 425
01:51 137
16:19 708
10:49 741
02:58 961
17 14:36
12:08 161
00:31 127
04:43 194
17:12 926
17:26 389
18:27 452
05:23 703
18:57 156
00:16 291
08:44 922
12:20 704
16:57 734
00:49 725
15:06 886
03:28 726
07:38 754
10:59 778
9 05:45
16:34 250
19:22 928
11:46 944
04:26 868
03:19 865
22:34 501
01:29 144
18:48 219
03:50 935
4 22:58
04:39 76
10:50 586
16:37 442
18:45 495
15 13:10
19:51 391
22:29 43
22:11 219
03:18 370
20:21 890
11:54 933
23:20 791
02:16 75
15:02 492
06:28 463
09:23 22
21:46 437
15:48 742
04:15 69
16:52 199
19 03:57
11:18 463
22:48 775
22:51 482
00:38 144
15:35 314
02:00 113
17:39 757
08:48 83
10:40 97
01:10 34
02:57 41
23:43 15
00:57 777
07:34 131
07:17 643
19:07 12
08:25 973
22:13 744
15:59 386
1 04:53
12:18 193
11 05:17
13:09 978
12:41 614
04:52 142
00:23 277
20:44 454
07:42 104
23:25 990
18:45 306
04:01 350
22:23 201
08:49 16
20 05:15
04:13 195
06:25 18
00:21 929
11:33 993
00:56 984
00:54 999
20:46 71
23:13 314
08:57 362
06:48 62
01:28 857
08:50 76
07:27 116
06:18 257
11:54 934
21:58 221
20:19 911
12:06 503
16:18 841
12:12 210
3 01:30
17:14 98
13:37 727
07:08 254
7 19:44
01:21 758
11:57 29
07:10 19
20:06 240
18:42 86
08:36 526
02:09 753
19 11:20
06:34 693
20:13 17
16:38 431
03:37 312
17:48 352
18:32 245
05:30 44
16:38 811
21:16 712
20:07 203
05:29 711
13:49 182
09:45 241
14:25 417
17:58 693
21:32 879
20:25 817
01:42 95
02:19 942
10 04:07
19:13 425
08:06 734
21:40 923
13:58 440
11:07 625
21:17 185
07:25 53
04:06 934
20:56 422
16:58 892
12 09:02
15:29 484
04:31 6
06:56 576
02:07 196
16:44 218
18:20 268
22:24 700
12:20 704
10:16 993
11:19 78
06:58 51
23:54 95
9 05:36
15:19 605
22:11 180
10:53 435
23:44 876
22:32 599
10:22 544
19:02 545
14:44 715
11:11 98
11 07:23
22:50 853
14:01 979
10:59 560
18:03 651
02:17 565
23:39 32
17:59 637
06:05 956
05:28 472
11:31 192
14:09 73
``````
AC output:

Code: Select all

``````Case 1: 564
Case 2: 308
Case 3: 94
Case 4: 112
Case 5: 1673
Case 6: 353
Case 7: 119
Case 8: 502
Case 9: 608
Case 10: 1271
Case 11: 510
Case 12: 367
Case 13: 352
Case 14: 350
Case 15: 151
Case 16: 1090
Case 17: 120
Case 18: 347
Case 19: 276
Case 20: 301
Case 21: 334
Case 22: 143
Case 23: 969
Case 24: 36
Case 25: 708
Case 26: 598
Case 27: 989
Case 28: 439
Case 29: 261
Case 30: 337
Case 31: 414
Case 32: 805
Case 33: 122
Case 34: 181
Case 35: 388
Case 36: 411
Case 37: 642
Case 38: 339
Case 39: 500
Case 40: 657
Case 41: 250
Case 42: 398
Case 43: 811
Case 44: 392
Case 45: 348
Case 46: 1465
Case 47: 340
Case 48: 533
Case 49: 249
Case 50: 461
Case 51: 535
Case 52: 1138
Case 53: 1353
Case 54: 771
Case 55: 256
Case 56: 595
Case 57: 702
Case 58: 510
Case 59: 977
Case 60: 992
Case 61: 222
Case 62: 348
Case 63: 643
Case 64: 398
Case 65: 271
Case 66: 1183
Case 67: 810
Case 68: 361
Case 69: 429
Case 70: 524
Case 71: 395
Case 72: 567
Case 73: 476
Case 74: 610
Case 75: 374
Case 76: 110
Case 77: 693
Case 78: 325
Case 79: 296
Case 80: 448
Case 81: 382
Case 82: 1574
Case 83: 548
Case 84: 128
Case 85: 840
Case 86: 417
Case 87: 899
Case 88: 417
Case 89: 421
Case 90: 348
Case 91: 638
Case 92: 228
Case 93: 88
Case 94: 592
Case 95: 262
Case 96: 331
Case 97: 251
Case 98: 215
Case 99: 433
Case 100: 440
``````
Check input and AC output for thousands of problems on uDebug!

B_sayem
New poster
Posts: 7
Joined: Wed Dec 11, 2013 7:57 pm

### Re: 11958 - Coming Home

Why i got wrong ans???

#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{

int n,k,ch,cm,ah,am,min1,min2,t,least,check=1;
cin>>n;
while(n>0)
{
least=0;
cin>>k;
cin>>ch;
cin.ignore();
cin>>cm;
min1=(ch*60)+cm;
while(k>0)
{
int temp;
cin>>ah;
cin.ignore();
cin>>am;
cin>>t;
if(((ah*60)+am)<=min1)
{
min2=((24*60)+(ah*60)+am+t);

}
else
{
min2=(ah*60)+am+t;
}

temp=min2-min1;
if(temp<least||least==0)
{
least=temp;
}
k--;
}

cout<<"Case "<<check<<": "<<least<<endl;
check++;
n--;
}
return 0;
}

brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 11958 - Coming Home

Input:

Code: Select all

``````1
2 18:00
18:00 0
18:01 0
``````
Output should be:

Code: Select all

``````Case 1: 0
``````
Check input and AC output for thousands of problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: 11958 - Coming Home

brianfry713,

Thanks for the great test cases.
Check input and AC output for over 7,500 problems on uDebug!

uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

### Re: uva 11958

brianfry713,

Thanks. These are some great test cases!
Check input and AC output for over 7,500 problems on uDebug!