https://codeforces.com/problemset/problem/1995/A

 

Problem - 1995A - Codeforces

 

codeforces.com

 

 

 

#전체 코드

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <climits>
using namespace std;
 
int main() {
    
    int t;
    cin >> t;
 
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> diagonals(n + 1, 2);
        diagonals[n] = 1;
 
        int placeCount = 0;
 
        while (k > 0) {
            for (int i = k; i > 0; i--) {
                if (i <= n && diagonals[i] > 0) {
                    k -= i;
                    diagonals[i]--;
                    placeCount++;
                    //cout << "k:" << k << '\n';
                    if (k == 0) {
                        break;
                    }
                    break;
                }
            }
        }
 
        cout << placeCount << '\n';
 
    }
 
 
 
}

 

'[Codeforces]' 카테고리의 다른 글

Codeforces Round 970 (Div. 3) A,B,C,D 풀이  (0) 2024.09.07
[Codeforces] Array Craft [C++]  (0) 2024.07.21
[Codeforeces] Submission Bait [C++]  (0) 2024.07.21

+ Recent posts