Cod sursa(job #2437324)
| Utilizator | Data | 9 iulie 2019 12:45:48 | |
|---|---|---|---|
| Problema | Transport | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.73 kb |
#include <fstream>
#include <algorithm>
using namespace std;
ifstream in("br.in");
ofstream out("br.out");
int main()
{
int n,t,v[15001],i,k,x,stotal=0,s;
in>>n>>t;
for(i=1;i<=n;i++)
{
in>>v[i];
stotal+=v[i];
}
for(i=0;i<t;i++)
{
in>>k>>x;
if(x>stotal)
out<<n<<'\n';
else
if(x<v[k])
out<<0<<'\n';
else
{
s=0;
while(x>0)
{
s++;
x-=v[k];
k++;
if(k>n)
k=1;
}
if(x<0)
s--;
out<<s<<'\n';
}
}
return 0;
}
