Advertisement
Saleh127

UVA 661

Jun 27th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n,m,c,j=0;
  6. while(scanf("%d %d %d",&n,&m,&c)==3)
  7. {
  8. if(n==0 && m==0 && c==0) break;
  9. int a[1000],b[1000],d,maxx=0,f=0,ans=0,i;
  10. for(i=0; i<n; i++)
  11. {
  12. cin>>b[i];
  13. a[i]=0;
  14. }
  15. for(i=0; i<m; i++)
  16. {
  17. cin>>d;
  18. if(a[d-1]==0)
  19. {
  20. ans+=b[d-1];
  21. a[d-1]=1;
  22. }
  23. else
  24. {
  25. ans-=b[d-1];
  26. a[d-1]=0;
  27. }
  28. if(ans>c)
  29. {
  30. f=1;
  31. }
  32. else{
  33. if(ans>maxx) maxx=ans;
  34. }
  35. }
  36. j++;
  37. if(f==1)
  38. printf("Sequence %d\nFuse was blown.\n\n",j);
  39. else
  40. printf("Sequence %d\nFuse was not blown.\nMaximal power consumption was %d amperes.\n\n",j,maxx);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement