Cod sursa(job #2600468)
| Utilizator | Data | 12 aprilie 2020 17:27:29 | |
|---|---|---|---|
| Problema | Deque | Scor | 100 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.54 kb |
#include <fstream>
#include <deque>
using namespace std;
ifstream f("deque.in");
ofstream g("deque.out");
deque<pair<int,int>>q;
int n,k;
long long suma=0;
int main()
{
f>>n>>k;
for(int i=1; i<=n; i++)
{
int x;
f>>x;
while(q.size() and q.front().second+k<=i)
q.pop_front();
while(q.size() and q.back().first>x)
{
q.pop_back();
}
q.push_back({x,i});
if(i>=k)
suma+=q.front().first;
}
g<<suma;
return 0;
}
