求助
查看原帖
求助
246822
Yhlo_Yzj楼主2022/2/20 11:58
#include <bits/stdc++.h>
using namespace std;
int n , m , k ,p;
int a[100005];
int main () {
	cin >> n >> m >> k >> p;
	if(n <= p || k < p){
		cout << "NO";
	}else{
		int sum = k / p;
		while(sum > m){
			sum --;
		}
		int ans = (k - sum * p) / (n - p);
		if(ans * (n - p) == (k - sum *p) && ans != sum){
			cout << "YES" << endl;
			for(int i = 1;i <= p;i ++){
				cout << sum << " " << m - sum << endl;
			}
			for(int i = 1;i <= n - p;i ++){
				cout << ans << " " << m -ans << endl;
			}
		}else{
			int pos = k - sum * p;
			if(n == p + 1 && pos == sum){
				cout <<"NO";
				return 0;
			}
			cout << "YES" << endl;
			for(int i = 1;i <= p;i ++){
				cout << sum << " " << m - sum << endl;
			}
			if(pos == sum){
				cout << pos - 1 << " " << m - pos + 1 << endl;
				if(pos == 1){
					return 0;
				}
				cout << 1 << " " << m - 1 << endl;
				for(int i = 1;i <= n - p - 2;i ++){
					cout << 0 << " " << m << endl; 
				}	
			}else{
				cout << pos << " "<< m -pos << endl;
				for(int i = 1;i <= n - p - 1;i ++){
					cout << 0 << " " << m << endl; 
				}			
			}
		}
	}
	return 0;
}

部分WA

2022/2/20 11:58
加载中...