This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
using namespace std;
long long countSubsequences(const vector<int>& arr, int n, long long k) {
long long result = 0;
// Iterate through all possible subsequences
for (int i = 0; i < n; ++i) {
for (int j = i; j < n; ++j) {
for (int l = j; l < n; ++l) {
for (int m = l; m < n; ++m) {
long long sum = 0;
// Calculate the sum of the current subsequence
for (int idx = i; idx <= m; ++idx) {
sum += arr[idx];
}
// Check if the sum is less than or equal to k
if (sum <= k) {
++result;
}
}
}
}
}
return result;
}
int main() {
int n;
long long k;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; ++i)
cin >> arr[i];
cin >> k;
long long result = countSubsequences(arr, n, k);
cout << result << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |