Cod sursa(job #1367652)
| Utilizator | Data | 1 martie 2015 23:59:51 | |
|---|---|---|---|
| Problema | Sortare prin comparare | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
#define DIM 5000002
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
int N,v[DIM],d[DIM],p,u,K;
long long sol;
int main(){
fin>>N>>K;
p=1;
u=0;
for(int i=1;i<=N;i++){
fin>>v[i];
while(p<=u && v[i]<v[d[u]])
u--;
d[++u]=i;
if(i-d[p]==K)
p++;
if(i>=K)
sol+=v[d[p]];
}
fout<<sol<<"\n";
fin.close();fout.close();
return 0;
}
