Cod sursa(job #1202893)
| Utilizator | Data | 30 iunie 2014 00:43:07 | |
|---|---|---|---|
| Problema | Deque | Scor | 60 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.59 kb |
#include <fstream>
#include <deque>
using namespace std;
ifstream is("deque.in");
ofstream os("deque.out");
int n, m;
long long answ;
int x[5000000];
deque<int> q;
int main()
{
is >> n >> m;
for ( int i = 1; i <= n; ++i )
{
is >> x[i];
while ( !q.empty() && x[i] <= x[q.back()] )
q.pop_back();
q.push_back(i);
if ( i < m )
continue;
if ( i - q.front() + 1 > m )
q.pop_front();
answ += x[q.front()];
}
os << answ;
is.close();
os.close();
return 0;
}
