1697A - Parkway Walk - CodeForces Solution


greedy implementation *800

Please click on ads to support us..

Python Code:

t=int(input())
for i in range(t):
    x=input()
    n=int(x.split()[0])
    m=int(x.split()[1])
    a=input()
    a1=a.split()
    for i in range(n):
        a1[i]=int(a1[i])
    if m>sum(a1): print(0)
    else: print(sum(a1)-m)

C++ Code:

#include <bits/stdc++.h>
using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int l;
  cin>>l;
  while(l--){
    int a, k;
    cin>>a>>k;
    int x, add = 0;
    for(int i = 0; i < a; i++){
      cin>>x;
      add += x;
    }
    if(add - k <= 0){
      cout<<0<<"\n";
    }
    else{
      cout<<(add-k)<<"\n";
    }
  }
}


Comments

Submit
0 Comments
More Questions

454B - Little Pony and Sort by Shift
1152A - Neko Finds Grapes
1719B - Mathematical Circus
1719C - Fighting Tournament
1642A - Hard Way
285C - Building Permutation
1719E - Fibonacci Strings
1696C - Fishingprince Plays With Array
1085A - Right-Left Cipher
1508B - Almost Sorted
1690C - Restoring the Duration of Tasks
1055A - Metro
1036D - Vasya and Arrays
1139C - Edgy Trees
37A - Towers
353A - Domino
409H - A + B Strikes Back
1262A - Math Problem
158C - Cd and pwd commands
194A - Exams
1673B - A Perfectly Balanced String
1104B - Game with string
1169B - Pairs
1567D - Expression Evaluation Error
78A - Haiku
1287A - Angry Students
1428A - Box is Pull
234B - Reading
581B - Luxurious Houses
1481C - Fence Painting