fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. const int N = 1e6+10;
  6.  
  7. ll a[N];
  8.  
  9. int main()
  10. {
  11. ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  12. int n,k,ri,rj;
  13. cin>>n>>k;
  14. for(int i=1;i<=n;i++)cin>>a[i];
  15. cin>>ri>>rj;
  16. if(rj<k){
  17. cout<<ri<<" "<<rj;
  18. return 0;
  19. }
  20. ll over=rj-k+1;
  21. for(int i=ri+1;i<=n;i++){
  22. if(a[i]<k){
  23. if(over>k-1-a[i])over-=k-1-a[i];
  24. else {
  25. cout<<i<<" "<<a[i]+over;
  26. return 0;
  27. }
  28. }else{
  29. over+=a[i]-k+1;
  30. }
  31. }
  32. int ansx=n+over/(k-1);
  33. if(over%(k-1)!=0)ansx++;
  34. int ansy=over%(k-1);
  35. if(over%(k-1)==0)ansy=k-1;
  36.  
  37. cout<<ansx<<" "<<ansy;
  38.  
  39. return 0;
  40. }
  41.  
Runtime error #stdin #stdout 4.64s 4376KB
stdin
Standard input is empty
stdout
Standard output is empty