CT28927

Dora's barrels Even Minus Odd

EasyL3 · Syntax SurferAcceptance: 0.0%XP: 20

Caravans arrive at the caldera rim of Firewatch with crates of barrels, and Dora the clerk must account for every last one. Task: Read n integers and print the sum of values at even 1-based positions minus the sum at odd positions. Input format: First line: n. Second line: n space-separated integers. Output format: Print (sum of even-positioned) - (sum of odd-positioned). Constraints: 1 <= n <= 227; -100 <= a[i] <= 1000; answers fit a signed 64-bit integer.

Example 1:

Input: 76 852 -48 159 998 169 347 229 12 325 861 766 661 935 418 72 949 367 575 904 980 41 206 509 802 -16 429 74 746 94 -86 970 772 217 495 22 594 467 394 937 560 361 396 -28 498 630 536 613 345 -31 -64 347 830 722 499 534 251 130 917 777 232 183 727 7 93 487 -24 821 159 653 -77 -5 522 639 -88 313 607
Output: -1778

Example 2:

Input: 205 953 7 544 689 80 -33 558 19 467 669 296 152 247 602 593 934 377 728 69 118 194 617 227 829 158 906 789 555 12 -65 570 10 462 421 -52 785 676 -79 -80 -26 541 721 856 -31 471 105 624 714 991 -48 150 409 275 242 629 297 204 455 564 871 146 243 25 509 352 377 697 867 455 513 664 377 719 503 91 631 941 341 119 874 -61 308 251 -8 945 26 590 98 -75 653 580 273 898 678 898 -24 280 26 707 678 331 304 457 410 78 726 -53 372 475 828 -36 613 262 576 880 863 467 385 711 854 101 371 699 311 684 535 554 570 836 343 575 811 309 169 300 469 368 249 795 814 671 836 819 964 577 709 323 608 950 161 670 343 958 85 391 224 145 233 576 365 304 663 846 272 852 291 871 344 377 394 974 563 673 409 0 189 906 553 258 623 652 190 203 706 13 865 295 -12 937 769 844 671 778 389 215 758 508 5 301 657 -8 265 -74 363 8…
Output: 3598

Example 3:

Input: 36 972 760 48 591 133 166 734 942 324 635 -38 175 710 -85 -52 48 852 304 376 455 45 390 213 977 948 231 602 343 628 39 549 566 824 918 45 792
Output: -334

Constraints:

1 <= n <= 227; -100 <= a[i] <= 1000; answers fit a signed 64-bit integer.

Loading...
Test Cases:No test cases
No test cases available.
Dora's barrels Even Minus Odd - EASY Coding Problem | CodeTikki