1316A - Grade Allocation - CodeForces Solution


implementation *800

Please click on ads to support us..

Python Code:

t=int(input())

for i in range(t):
    l=list(map(int,input().split()))
    y=list(map(int,input().split()))
    y=sum(y)
    if y<=l[1]:
        print(y)
    else:
        print(l[1])

C++ Code:

//Idk how it works but it works
//¯\_(ツ)_/¯

#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>

using namespace std;

#define int long long
#define ll long long
#define cy cout << "YES"
#define cn cout << "NO"
#define eb emplace_back
#define itn int
#define fro for
#define cotu cout
#define forn( i, n ) for( int i = 0; i < n; i++ )

void output(bool fl) {
    if(fl) cy;
    else cn;
    cout << endl;
}

bool isPalindrom (string s){
    bool fl = true;
    for(int i = 0; i < s.size() / 2; i++) {
        if(s[i] != s[s.size() - 1 - i]){
            fl = false;
            return fl;
        }
    }
    return fl;
}

int sumOfNumbers(int n) {
    int res = 0;
    while(n > 0) {
        res += n % 10;
        n = n / 10;
    }
    return res;
}

void solve () {
    int n, m;
    cin >> n >> m;
    int res = 0;
    for(int i = 0; i < n; i++) {
        int x;
        cin >> x;
        res += x;
    }
    cout << min(m, res) << endl;
    return;
}

main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin.exceptions(ios::badbit | ios::failbit);
    setlocale( LC_ALL, "Ukr" );

    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢛⡛⠛⡛⠄⠝⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠋⣤⣦⠶⣷⣆⢀⡝⠛⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢂⣽⠏⠄⠄⠄⠈⢻⣧⢨⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠡⣸⡏⠄⠄⠄⠄⠄⠄⢿⣇⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡿⠿⠿⠿⠿⠟⠛⠛⠛⠛⠛⠟⠻⢋⢼⡟⠄⠄⠄⠄⠄⠄⠄⢸⣯⢈⢹⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⢰⣿⣿⣿⣿⣿⣿⣿⡿⠿⠛⠛⠉⠉⠉⠣⠄⠄⠄⠄⠄⠄⠄⣼⡧⠠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡘⢿⣿⣿⣍⡩⠙⠁⠄⠄⠄⠄⠄⠄⠄⠄⠈⢂⠄⠄⠄⠄⣰⣿⣞⢰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣦⡙⡿⠋⠄⠄⠄⡀⠤⠄⠤⠄⠄⠄⠄⠄⠄⡆⠄⠄⣼⡟⠤⢈⠑⡙⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⡿⠡⠁⠄⠄⠄⡌⣰⣾⣿⣷⡄⢢⠄⠄⠄⠄⢱⢀⡾⣧⣭⣿⣆⢁⠐⡜⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⢧⠃⠄⠄⠄⠄⠇⢿⣿⣿⣿⡟⡸⠄⠄⠄⠄⠸⠿⡉⢹⣿⣿⡿⠸⠄⠐⠹⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡿⠈⠄⠄⠄⠄⠄⠈⠢⢉⣛⡩⠔⠁⢀⠄⠄⠄⣠⡄⠄⠄⡑⠉⠐⠁⠄⠄⡇⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡇⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⢴⣚⣿⣿⣖⡖⠁⠄⠄⠄⠄⠄⢠⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡇⠁⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⡟⠛⠛⢿⠃⠄⠄⠄⠄⠄⠄⠘⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠒⠒⠄⠄⠄⠄⠄⠄⠄⠄⡆⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡏⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢀⢰⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⢟⣡⠄⠄⠄⠄⠄⠄⠄⠂⢀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠒⢝⢿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠑⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠃⠄⠄⢢⢻⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠰⢀⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠇⠄⠄⢀⢺⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⡇⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠑⠂⠠⢄⠄⠄⠄⠄⠄⢀⠔⠁⠄⠄⣠⢊⣾⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⣿⠃⠄⠄⠄⠄⠄⠄⠄⠈⠐⠒⠢⠤⠤⠤⠄⠄⠂⠄⠄⠄⠄⠣⠤⠒⠂⠁⠄⢜⢿⣿⣿⣿⣿⣿
//⣿⣿⣿⢸⡟⠄⠄⠄⠄⠄⠄⠄⠄⠈⠁⠂⢄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⡜⣿⣿⣿⣿⣿
//⣿⣿⣿⣌⢳⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⢢⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⡺⠆⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⡄⢿⣿⣿⣿⣿
//⣿⣿⣿⡇⡇⣮⠢⣠⡶⢶⡀⠄⠄⠄⠄⠄⠠⠴⠄⡀⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠄⠈⠐⢝⢿⣿⣿
//⣿⣿⣿⣧⢧⣉⣾⡋⠥⢺⣧⠄⣀⡀⠄⠄⠄⠄⠄⠈⠳⡀⠤⠤⠤⣀⣒⣬⣭⣤⣀⣀⣒⣂⡠⠤⠤⣸⣿⣿
//⣿⣿⣿⣿⣿⣷⣬⣙⣛⠶⢟⣼⣷⣶⣶⣮⣭⣥⣖⣒⣒⣵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
//⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿


Comments

Submit
0 Comments
More Questions

Differences of the permutations
Doctor's Secret
Back to School
I am Easy
Teddy and Tweety
Partitioning binary strings
Special sets
Smallest chosen word
Going to office
Color the boxes
Missing numbers
Maximum sum
13 Reasons Why
Friend's Relationship
Health of a person
Divisibility
A. Movement
Numbers in a matrix
Sequences
Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making