双指针 小红统计区间 牛客周赛 Round 28

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 10;
ll a[N];

int main(){
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    ll n,k;
    cin >> n >> k;
    for(int i = 1; i <= n; i++) cin >> a[i];
    int left = 1;
    ll sum = 0;
    ll ans = 0;
    for(int right = 1; right <= n; right++){
        sum += a[right];
        while(sum >= k){
            sum -= a[left];
            left++;
        }
        ans += left - 1;
    }
    cout << ans;
	return 0;
}
相关推荐
XH华37 分钟前
C++语言第二章类和对象(下)
开发语言·c++
从零开始的代码生活_1 小时前
C++ stack、queue 与 priority_queue:容器适配器原理与实战
开发语言·c++·后端·学习·算法
晚笙coding1 小时前
LeetCode 226. 翻转二叉树(Invert Binary Tree)
算法·leetcode·职场和发展
2zcode1 小时前
项目文档:基于MATLAB低采样率ISAR成像的快速稀疏重建算法研究
开发语言·算法·matlab
哈里沃克2 小时前
编译与链接 - 02
算法
巴糖2 小时前
Embedding了解一些
算法
战族狼魂2 小时前
广东备案大模型超百款
人工智能·算法·大模型·大语言模型
千桐科技2 小时前
🚀 qModel 算法模型平台v1.2.0 开源版发布!Python 模型接入链路全面升级,告别“能跑但上不了线”的尴尬
后端·算法·llm
刘沅2 小时前
LeetCode 93.复原IP地址
算法·面试
AA陈超2 小时前
003 XiYou 西游 — P0 阶段实施计划
c++·笔记·学习·ue5