Codeforces Round #839 (Div. 3) 1772C - Different Differences Solution
Problem Link: https://codeforces.com/contest/1772/problem/C
Solution in C++:
- /// La ilaha illellahu muhammadur rasulullah
- ///******Bismillahir-Rahmanir-Rahim******///
- /// Abul Hasnat Tonmoy
- /// Department of CSE,23rd batch
- /// Islamic University,Bangladesh
- ///**********ALLAH IS ALMIGHTY************///
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long int
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- ll n, t, i;
- cin >> t;
- while (t--) {
- ll k;
- cin >> k >> n;
- set<int> ans;
- ll sum = 1;
- for (i = 1; sum <= n && ans.size() < k; sum += i++) ans.insert(sum);
- for (i = n; i >= 1 && ans.size() < k; i--) ans.insert(i);
- for (auto i : ans) cout << i << " ";
- cout << endl;
- }
- }
No comments