Pagini recente » Cod sursa (job #978350) | Cod sursa (job #550558) | Cod sursa (job #718978) | Cod sursa (job #3004131) | Cod sursa (job #964707)
Cod sursa(job #964707)
#include<fstream>
#include<set>
using namespace std;
ifstream fin("deque.in");
ofstream fout("deque.out");
int n,k,i,suma, v[5000010];
multiset<int> s;
multiset<int>::iterator it;
int main()
{
fin>>n>>k;
for(i=1;i<=n;i++)
fin>>v[i];
for(i=1;i<=k;i++)
{
s.insert(v[i]);
}
it = s.begin();
suma += *it;
for(i=k+1;i<=n;i++){
s.insert(v[i]);
s.erase(v[i-k]);
it=s.begin();
suma +=*it;
}
fout<<suma;
return 0;
}