PROBLEM LINK:
Practice
Author: mrslowmo
Editorialist: mrslowmo
DIFFICULTY:
MEDIUM
PREREQUISITES:
Math
PROBLEM:
Find the position of each of the soldiers after a given time.
EXPLANATION:
Note that the relative positions of the soldiers never changes. That is, the soldiers 1, 2, . . . , N are aligned clockwise in this order.
Hence now, we just need to calculate there each soldier’s position and sort them. We would also need to count the number of meetings.
We combine both observations to get the result.
SOLUTIONS:
Setter's Solution
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
int n,l,t;
cin >> n >> l >> t;
int ans[n];
int cnt=0;
for(int i=0,x,w;i<n;i++){
cin >> x >> w;
if (w == 1)
x += t;
else
x -= t;
// calculating number of meetings
cnt=((cnt+(int)floor(1.0*x/l))%n+n)%n;
// calculating position of each soilder
ans[i]=(x%l+l)%l;
}
sort(ans,ans+n);
for(int i=0; i<n;i++)
cout << ans[(cnt+i)%n] << endl;
return 0;
}