Advertisement
MiinaMagdy

661 - Blowing Fuses

Sep 2nd, 2022
850
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  12.     int n, m, c;
  13.     int test = 0;
  14.     char report[2][100] = {
  15.         "Fuse was blown.",
  16.         "Fuse was not blown.\nMaximal power consumption was "
  17.     };
  18.     while (scanf("%d %d %d", &n, &m, &c), n || m || c) {
  19.         printf("Sequence %d\n", ++test);
  20.         bool is_fuse_safe = true;
  21.         bool is_device_turned[n + 1]{};
  22.         int consumption[n + 1];
  23.         int amperes = 0;
  24.         int Maxial_power_consumption = 0;
  25.         for (int i = 1; i <= n; i++) {
  26.             scanf("%d", &consumption[i]);
  27.         }
  28.         int switch_device;
  29.         while (m--) {
  30.             scanf("%d", &switch_device);
  31.             is_device_turned[switch_device] ^= 1;
  32.             amperes += (is_device_turned[switch_device] ? 1 : -1) * consumption[switch_device];
  33.             Maxial_power_consumption = max(Maxial_power_consumption, amperes);
  34.             is_fuse_safe &= (amperes <= c);
  35.         }
  36.         printf("%s", report[is_fuse_safe]);
  37.         if (is_fuse_safe) printf("%d amperes.", Maxial_power_consumption);
  38.         printf("\n\n");
  39.     }
  40. }
  41.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement