답안 #703659

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
703659 2023-02-28T04:39:47 Z Chal1shkan Fountain (eJOI20_fountain) C++14
30 / 100
1500 ms 3908 KB
# include <bits/stdc++.h>
 
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
# define deb(x) cerr << #x  << " = " << x << endl; 
# define pll pair <ll, ll>

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const ll maxn = 1e5 + 25;
const ll inf = 2e9 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
 
using namespace std;

ll n, q;
pll p[maxn];

void ma1n (/* SABR */)
{
	cin >> n >> q;
	for (ll i = 1; i <= n; ++i)
	{
		cin >> p[i].ff >> p[i].ss;
	}
	p[n + 1] = {inf, inf};
	while (q--)
	{
		ll id, v;
		cin >> id >> v;
		if (v > p[id].ss)
		{
			ll last = id, ans = id;
			v -= p[id].ss;
			for (ll i = id + 1; i <= n + 1; ++i)
			{
				if (p[i].ff > p[last].ff)
				{
					if (v > p[i].ss)
					{
						v -= p[i].ss;
						last = i;
					}
					else
					{
						ans = i;
						break;
					}
				}
			}
			if (ans == n + 1) ans = 0;
			cout << ans << nl;
		}
		else
		{
			cout << id << nl;
		}
	}
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
//  freopen("file.in", "r", stdin);
//  freopen("file.out", "w", stdout);
    int ttt = 1;	
//  cin >> ttt;
    for (int test = 1; test <= ttt; ++test)
    {
//      cout << "Case " << test << ":" << ' ';
        ma1n();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1560 ms 3908 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Execution timed out 1560 ms 3908 KB Time limit exceeded
9 Halted 0 ms 0 KB -