Submission #407204

# Submission time Handle Problem Language Result Execution time Memory
407204 2021-05-18T15:53:02 Z victoriad Fountain (eJOI20_fountain) C++14
30 / 100
1500 ms 3868 KB
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
#include <queue>
#include <map>
#include <iomanip>
#include <stack>
#include <fstream>
using namespace std;
 
 
int main(){
  ios::sync_with_stdio(false);
   cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    int vo,r,l;
    vector<long long int>v(n);
    vector<long long int>d(n);
    for(int i=0;i<n;i++){
      cin>>d[i]>>v[i];
    }
	vector<int>con(n);
	for(int i=0;i<n;i++){
		bool b=false;
		for(int k=i;k<n;k++){
			if(d[i]<d[k]){
				con[i]=k;
				b=true;
				break;
			}
		}
		if(!b)con[i]=-1;
	}
    
    for(int i=0;i<q;i++){
      cin>>r>>l;
      r--;
      l-=v[r];
      if(l<=0)cout<<r+1<<"\n";
      else{
		  int i=r;
        while(l>0 || i!=-1){
			l-=v[con[i]];
			if(con[i]==-1){
				cout<<0<<"\n";
				break;
			}
			if(l<=0){
				cout<<con[i]+1<<"\n";
				break;
			}
			i=con[i];
		}
		if(i==-1)cout<<0<<"\n";
      }
    }
  return 0;
}

Compilation message

fountain.cpp: In function 'int main()':
fountain.cpp:20:9: warning: unused variable 'vo' [-Wunused-variable]
   20 |     int vo,r,l;
      |         ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1576 ms 3868 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Execution timed out 1576 ms 3868 KB Time limit exceeded
9 Halted 0 ms 0 KB -